18

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!

8
  • Can you include in the post the output of 'ls -lah /var/run/docker.sock' ? Commented Aug 9, 2018 at 11:51
  • @Neekoy added the command's output Commented Aug 9, 2018 at 12:04
  • The docker socket is alright. Can you also run 'id' and paste the output? Commented Aug 9, 2018 at 12:30
  • Can you run groups command and see if docker is in the list? Commented Aug 9, 2018 at 13:06
  • @Neekoy i added the id output Commented Aug 12, 2018 at 5:30

2 Answers 2

49

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:

  1. kill tmux:

pkill -f tmux

  1. open tmux and test docker:

docker run hello-world

now it works fine

Sign up to request clarification or add additional context in comments.

Comments

1

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

1 Comment

~/.docker/ does not exist in my filesystem

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.