Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Running docker without sudo on Ubuntu 14.04 [closed]

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?

like image 498
luqo33 Avatar asked Mar 22 '15 21:03

luqo33


People also ask

Can I run docker without Sudo?

If you're running Linux in a virtual machine, it may be necessary to restart the virtual machine for changes to take effect. Verify that you can run docker commands without sudo . This command downloads a test image and runs it in a container. When the container runs, it prints a message and exits.

Should docker be run as root?

Running the container as root brings a lot of risks. Although being root inside the container is not the same as root on the host machine (some more details here) and you're able to deny a lot of capabilities during container startup, it is still the recommended approach to avoid being root .


2 Answers

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

newgrp docker
like image 181
zSprawl Avatar answered Sep 16 '22 14:09

zSprawl


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)
like image 38
lsowen Avatar answered Sep 17 '22 14:09

lsowen