docker.sock permission denied

2019-03-14 12:35发布

When I try to run simple docker commands like:

$ docker ps -a

I get an error message:

Got permission denied ... /var/run/docker.sock: connect: permission denied

When I check permissions with

$ ls -al /var/run/

I see this line:

srw-rw---- root docker docker.sock

So, I follow an advice from many forums and add local user to docker group:

$ sudo usermod -aG docker $USER

But it does not help. I still get the very same error message. How can I fix it?

标签: linux docker
4条回答
唯我独甜
2楼-- · 2019-03-14 12:58

As mentioned earlier in the comment the changes won't apply until your re-login. If you were doing a SSH and opening a new terminal, it would have worked in new terminal

But since you were using GUI and opening the new terminal the changes were not applied. That is the reason the error didn't go away

So below command did do its job, its just a re-login was missed

sudo usermod -aG docker $USER
查看更多
ら.Afraid
3楼-- · 2019-03-14 13:04

For those new to the shell, the command:

$ sudo usermod -aG docker $USER

needs to have $USER defined in your shell. This is often there by default, but you may need to set the value to your login id in some shells.


Changing the groups of a user does not change existing logins, terminals, and shells that a user has open. To avoid performing a login again, you can simply run:

$ newgrp docker

to get access to that group in your current shell.


Once you have done this, the user effectively has root access on the server, so only do this for users that are trusted with unrestricted sudo access.

查看更多
成全新的幸福
4楼-- · 2019-03-14 13:08

As my user is and AD user, I have to add the AD user to the local group by manually editing /etc/group file. Unforrtunately the adduser commands do not seem to be nsswitch aware and do not recognize a user not locally defined when adding someone to a group.

Then reboot or refresh /etc/group. Now, you can use docker without sudo.

Regards.

查看更多
走好不送
5楼-- · 2019-03-14 13:14
  1. Make sure your $USER variable is set

$ echo $USER

$ sudo usermod -aG docker $USER

  1. logout
  2. Upon login, restart the docker service

$ sudo systemctl restart docker

$ docker ps

查看更多
登录 后发表回答