I am trying to run docker without sudo on ubuntu 16.04. I followed the Linux post-installation instructions on the docker website:
sudo groupadd docker
sudo usermod -aG docker $USER
I rebooted and then ran
docker ps
this error still appears:
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.37/containers/json: dial unix /var/run/docker.sock: connect: permission denied
the weird thing is if i ssh from my machine to itself the command is executed correctly. when i run the command from tty it also works correctly.
edit:
output of ls -lah /var/run/docker.sock:
srw-rw---- 1 root docker 0 Aug 9 11:22 /var/run/docker.sock
output of id:
uid=1000(uname) gid=1000(uname) groups=1000(uname),4(adm),24(cdrom),27(sudo),29(audio),30(dip),46(plugdev),113(lpadmin),128(sambashare),999(docker)
what could have gone wrong? thanks for the help!
1. Introduction. Running Docker commands with sudo ensures that the Docker command is executed with the security rights of root (by using sudo) or by a user who is a member of the docker group.
So apparently the problem was the tmux shell.
The problem occurs when an account is added to the docker group, while still having at least one tmux session open. closing all tmux sessions solves the problem [the group accounts will now be updated in the next session].
solution:
pkill -f tmux
docker run hello-world
now it works fine
If you initially ran Docker CLI commands using sudo before adding your user to the docker group you may get this error the you need to remove the ~/.docker/ directory (it is recreated automatically, but any custom settings are lost), or change its ownership and permissions using the following commands:
$ sudo chown "$USER":"$USER" /home/"$USER"/.docker -R
$ sudo chmod g+rwx "/home/$USER/.docker" -R
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With