19

I attempted to set up Docker so that I do not have to type sudo before using it.

The steps that I took:

  1. I started with creating a docker group with sudo groupadd docker;
  2. I added my current user to the "docker" group with sudo gpasswd -a ${USER} docker;
  3. I restarted docker with sudo service docker restart;
  4. I closed and opened the terminal to start a new session.

After running docker run hello-world, I receive this output:

FATA[0000] Post http:///var/run/docker.sock/v1.17/containers/create: dial unix /var/run/docker.sock: permission denied. Are you trying to connect to a TLS-enabled daemon without TLS?

One thing that puzzles (and might give a hint about why I cannot run docker without sudo) is the output of:

$ groups: is:

ltarasiewicz adm cdrom sudo dip plugdev lpadmin sambashare

(no "docker" group)

The output of $ groups ltarasiewicz:

ltarasiewicz adm cdrom sudo dip plugdev lpadmin sambashare docker

("docker" is one of the groups)

What might be the reason for the fact that I still cannot use Docker withou sudo after adding my current user to the "docker" group?

luqo33
  • 8,001
  • 16
  • 54
  • 107
  • 2
    Beware that running Docker without sudo is dangerous, make sure to understand the associated security risks. See https://medium.com/@msuixo/linux-users-running-docker-without-sudo-is-dangerous-3e5c5654abea – Mickaël Oct 02 '18 at 09:59

3 Answers3

21

Run the following command at the end to apply group settings:

newgrp docker
zSprawl
  • 969
  • 7
  • 11
20

Group changes don't take effect immediately in the currently logged in session. Your options include:

  1. Log out then log back in
  2. Start a new login session (for bash this is with the bash -l command)
lsowen
  • 3,728
  • 1
  • 21
  • 23
  • 3
    Indeed, the solution is to log out from the current session and then log in again. I was wrongly convinced that closing and opening the terminal will do the job of applying the group changes. – luqo33 Mar 22 '15 at 21:41
  • Running the 'id' command should show 'docker' in the groups list – Roei Bahumi Mar 29 '17 at 13:56
5

Closing terminal or logging out wasn't enough in my case, I had to do a complete reboot.

JohnP
  • 1,046
  • 2
  • 16
  • 29