How to fix "dial unix /var/run/docker.sock: connect: permission denied" when group permissions seem correct?

DockerUbuntu 18.04

Docker Problem Overview


I'm suddenly having issues after an update of Ubuntu 18.04: previously I've used docker without issue on the system, but suddenly I cannot. As far as I can tell, the permissions look correct:

$ docker run hello-world
docker: Got permission denied while trying to connect to the Docker daemon socket at unix:///var/run/docker.sock: Post http://%2Fvar%2Frun%2Fdocker.sock/v1.35/containers/create: dial unix /var/run/docker.sock: connect: permission denied.
See 'docker run --help'.
$ ls -last /var/run/docker.sock 
0 srw-rw---- 1 root docker 0 Jul 14 09:10 /var/run/docker.sock
$ whoami
brandon
$ cat /etc/group | grep docker
docker:x:995:brandon
nvidia-docker:x:994:

EDIT:

Group information:

$ groups
brandon
$ groups brandon
brandon : brandon adm cdrom sudo dip plugdev games lpadmin sambashare docker
$ whoami
brandon

Update

Since the original post where I upgraded a system from 17.04 to 18.04, I've done two upgrades from 16.04 to 18.04, and neither of the later systems had the issue. So it might be something to do with the 17.04 to 18.04 upgrade process. I've yet to perform a fresh 18.04 installation.

Docker Solutions


Solution 1 - Docker

sudo setfacl --modify user:<user name or ID>:rw /var/run/docker.sock

It doesn't require a restart and is more secure than usermod or chown.

as @mirekphd pointed out, the user ID is required when the user name only exists inside the container, but not on the host.

Solution 2 - Docker

add the user to the docker group.

sudo usermod -aG docker $USER
sudo reboot

Solution 3 - Docker

Ubuntu 18:04

sudo setfacl --modify user:$USER:rw /var/run/docker.sock

Solution 4 - Docker

The way to fix it is to run:

sudo addgroup --system docker
sudo adduser $USER docker
newgrp docker

that works for me :)

Solution 5 - Docker

Just try to give the right permission to docker.sock file by:

sudo chmod 666 /var/run/docker.sock

Solution 6 - Docker

Somehow, i found this page when i have't correct permissons on my docker.sock after my Docker installation. So, if you have the same issue, you can read this:

> $ sudo adduser $USER docker does not work because the group is "root" > not "docker" > > $ ls -l /var/run/docker.sock srw-rw---- 1 root root 0 Jul 11 09:48 > /var/run/docker.sock so it should be $ sudo adduser $USER root > > from a non-snap installed machine, the group is "docker" > > # ls -l /var/run/docker.sock srw-rw---- 1 root docker 0 Jul 3 04:18 /var/run/docker.sock The correct way is, according to docker.help you > have to run the followings BEFORE sudo snap install docker > > $ sudo addgroup --system docker $ sudo adduser $USER docker $ newgrp > docker then the group will be "docker" > > $ ls -l /var/run/docker.sock srw-rw---- 1 root docker 0 Jul 11 10:59 > /var/run/docker.sock

Source: https://github.com/docker-archive/docker-snap/issues/1 (yes, first issue :D)

The easyest way to fix it is to run:

$ sudo setfacl -m "g:docker:rw" /var/run/docker.sock

And then, as it already metioned, run following commands for your user:

$sudo addgroup --system docker
$sudo adduser $USER docker
$newgrp docker

That's it :) Have fun!

Solution 7 - Docker

I did the quick fix and it worked immediately.

sudo chmod 777 /var/run/docker.sock

Solution 8 - Docker

Specific to Ubuntu, there is a known issue with lightdm that removes secondary groups from the user as part of the GUI login. You can follow that issue here: https://bugs.launchpad.net/lightdm/+bug/1781418

You can try switching off of lightdm or apply the workaround mentioned in the bug report:

> [Comment out the below lines from /etc/pam.d/lightdm:] > > auth optional pam_kwallet.so > auth optional pam_kwallet5.so

Temporary options include logging into your machine with something like an ssh or su -l command, or running the newgrp docker command. These will only affect the current shell and would need to be done again with each new terminal.


Outside of this issue, the general commands to give a user direct access to the docker socket (and therefore root access to the host) are:

sudo usermod -aG docker $(id -un) # you can often use $USER in place of the id command
newgrp docker # affects the current shell, logging out should affect all shells

Solution 9 - Docker

It looks like a permission issue:

sudo addgroup --system docker
sudo adduser $USER docker
newgrp docker
sudo setfacl -m "g:docker:rw" /var/run/docker.sock

Solution 10 - Docker

I was able to solve this on my Linux Machine using the below command.

> sudo setfacl --modify user:$USER:rw /var/run/docker.sock

Note: Please checck if you have sudo access. Otherwise this command will fail.

How to check sudo access?

$ whoami
> rahul
$ groups
> useracc
$ groups useracc
> Here you can see sudo and other access details.

Solution 11 - Docker

I fixed this issue by using the following command:

sudo chmod -x /var/run/docker.sock

Solution 12 - Docker

Please note: not only group name is important, but apparently also gid of the groups. So if docker group on host system has gid of i.e. 995,

cat /etc/group | grep docker  
docker:x:995:brandon

You must make sure gid of docker group You can do this as a part of a launch script, or simply by using exec and doing it manually:

groupmod -g 995 docker

Hope it helps anyone who comes here, it took me a while to find this answear.

Attributions

All content for this solution is sourced from the original question on Stackoverflow.

The content on this page is licensed under the Attribution-ShareAlike 4.0 International (CC BY-SA 4.0) license.

Content TypeOriginal AuthorOriginal Content on Stackoverflow
QuestionbbarkerView Question on Stackoverflow
Solution 1 - DockerNahshon pazView Answer on Stackoverflow
Solution 2 - DockerKaren DanielyanView Answer on Stackoverflow
Solution 3 - DockerAlex SandroView Answer on Stackoverflow
Solution 4 - DockerFahd RahaliView Answer on Stackoverflow
Solution 5 - DockerPejman KheyriView Answer on Stackoverflow
Solution 6 - DockerGoldusView Answer on Stackoverflow
Solution 7 - DockerparthView Answer on Stackoverflow
Solution 8 - DockerBMitchView Answer on Stackoverflow
Solution 9 - DockerPraveen Kumar K SView Answer on Stackoverflow
Solution 10 - DockerrahulnikhareView Answer on Stackoverflow
Solution 11 - DockerahmnouiraView Answer on Stackoverflow
Solution 12 - DockerButtheadView Answer on Stackoverflow