Portainer:尝试连接到 Docker 守护程序套接字时获得权限被拒绝

Portainer: Got permission denied while trying to connect to the Docker daemon socket

我正在使用 Docker 版本 19.03.11 附带的全新 Fedora CoreOS。

我的 core 用户在 docker 组中:

[core@localhost ~]$ groups
core adm wheel sudo systemd-journal docker

deployment instructions for portainer 之后,我像这样创建了一个新的 Portainer 容器(如 coreroot,这甚至都不重要):

$ docker volume create portainer_data
$ docker run -d -p 9000:9000 -p 8000:8000 --name portainer --restart always -v /var/run/docker.sock:/var/run/docker.sock -v portainer_data:/data portainer/portainer

当我尝试连接到本地守护进程时:

/var/run/docker.sock 的权限:

[core@localhost ~]$ ll /var/run/docker.sock
srw-rw----. 1 root docker 0 Aug  2 10:02 /var/run/docker.sock

即使我chmod o+rw/var/run/docker.sock也没用。这表明问题可能出在容器本身,所以我尝试访问它但我不能:

[core@localhost ~]$ docker exec -it portainer sh
OCI runtime exec failed: exec failed: container_linux.go:349: starting container process caused "exec: \"sh\": executable file not found in $PATH": unknown

目前我找到的所有资源都建议将用户添加到 docker 组,我这样做了,重启机器,我这样做了,或者在 /var/run/docker.sock 上设置 666,我这样做了但宁愿不要。没有任何帮助。

知道哪里出了问题以及如何解决吗?

感谢 Portainer Discord 上的 MrPaperbag,我发现这是因为 SELinux 的限制。

在此处找到解决方案:https://nanxiao.me/en/selinux-cause-permission-denied-issue-in-using-docker/

运行 docker run--privileged,或者使用 setenforce 0 将 SELinux 模式设置为宽松模式。可能有一种方法可以正确配置 SELinux,而不仅仅是绕过它,但是,对于我的用例来说,这已经足够了。

如果是SELinux问题,先按照portainer/portainer issue 849

试试

Correct way is to add :z to the volume mapping, so you're not defeating the purpose of docker.

Like so:

docker run -d -p 9000:9000 -v /var/run/docker.sock:/var/run/docker.sock:z portainer/portainer

Also we need a way to add the z or Z flag in Portainer for new containers. This has been a feature since 1.7 e.g. 2015 in Docker.

那个,或者用dpw/selinux-dockersock

命令中一切正常。我复制了它,它在我的配置下运行良好:

ls -la /var/run/ | grep docker
drwx------  8 root                root                 180 Aug  1 14:40 docker
-rw-r--r--  1 root                root                   4 Aug  1 14:29 docker.pid
srw-rw----  1 root                docker                 0 Aug  1 14:29 docker.sock
getenforce 
Permissive

如果这些不能解决问题,我会尝试卸载预装的 docker。你可能永远不知道他们使用了哪些黑幕设置。