我在Ubuntu 18.04 LTS上运行docker
时遇到权限问题。
有很多帖子描述了sudo usermod -a -G docker $USER
的修复,但是,这对我不起作用。
这是错误:
myuser@ubuntu:~$ docker container ls
Got permission denied while trying to connect to the Docker daemon socket at unix:///var/run/docker.sock: Get http://%2Fvar%2Frun%2Fdocker.sock/v1.39/containers/json: dial unix /var/run/docker.sock: connect: permission denied
运行usermod
myuser@ubuntu:~$ sudo usermod -a -G docker $USER
确认我的用户名在docker组中:
myuser@ubuntu:~$ cat /etc/group | grep docker
docker:x:129:myuser
也尝试过:
然后:
myuser@ubuntu:~$ docker container ls
Got permission denied while trying to connect to the Docker daemon socket at unix:///var/run/docker.sock: Get http://%2Fvar%2Frun%2Fdocker.sock/v1.39/containers/json: dial unix /var/run/docker.sock: connect: permission denied
...同样的问题!
当我使用sudo
myuser@ubuntu:~$ sudo !!
sudo docker container ls
CONTAINER ID IMAGE COMMAND CREATED STATUS PORTS NAMES
18b3719b66d2 postgres:10.3 "docker-entrypoint.s…" 27 minutes ago Up 27 minutes 0.0.0.0:5432->5432/tcp local-postgres10.3
有什么想法吗?
答案 0 :(得分:0)
在Centos 7.6(在AWS上为ami-04cf43aca3e6f3de3
)上,我发现该套接字归root:root
所有,并且docker组称为dockerroot
(请参阅/etc/group
)
使用chgrp和usermod解决,如下所示:
# ll /var/run/docker.sock
srw-rw----. 1 root root 0 Mar 22 16:40 /var/run/docker.sock
# chgrp dockerroot /var/run/docker.sock
# usermod -aG dockerroot USER_HERE
# ll /var/run/docker.sock
srw-rw----. 1 root dockerroot 0 Mar 22 16:40 /var/run/docker.sock
# su - USER_HERE
$ docker ps
CONTAINER ID IMAGE ...
...
感谢问题注释中的@gracefulrestart。