Ask Ubuntu is a question and answer site for Ubuntu users and developers. It's 100% free.

Sign up
Here's how it works:
  1. Anybody can ask a question
  2. Anybody can answer
  3. The best answers are voted up and rise to the top

On Docker's documentation pages, all example commands are shown without sudo, like this one:

docker ps

On Ubuntu, the binary is called docker.io. It also does not work without sudo:

sudo docker.io ps

How can I configure Docker so that I don't need to prefix every Docker command with sudo?

share|improve this question
    
Don't forget to enable ufw ;) – Rinzwind Jun 6 '14 at 8:29
1  
On Ubuntu 14.04 there is also 'docker' binary. – anatoly techtonik Sep 7 '14 at 8:55
up vote 358 down vote accepted
+100

The docker manual has this to say about it:

Giving non-root access

The docker daemon always runs as the root user, and since Docker version 0.5.2, the docker daemon binds to a Unix socket instead of a TCP port. By default that Unix socket is owned by the user root, and so, by default, you can access it with sudo.

Starting in version 0.5.3, if you (or your Docker installer) create a Unix group called docker and add users to it, then the docker daemon will make the ownership of the Unix socket read/writable by the docker group when the daemon starts. The docker daemon must always run as the root user, but if you run the docker client as a user in the docker group then you don't need to add sudo to all the client commands. As of 0.9.0, you can specify that a group other than docker should own the Unix socket with the -G option.

Warning: The docker group (or the group specified with -G) is root-equivalent; see Docker Daemon Attack Surface details.

Example:

  • Add the docker group if it doesn't already exist:

    sudo groupadd docker
    
  • Add the connected user "${USER}" to the docker group. Change the user name to match your preferred user:

    sudo gpasswd -a ${USER} docker
    
  • Restart the Docker daemon:

    sudo service docker restart
    
  • If you are on Ubuntu 14.04-15.10* use docker.io instead:

    sudo service docker.io restart
    
    • (If you are on Ubuntu 16.04 the service is named "docker" simply)
  • Either do a newgrp docker or log out/in to activate the changes to groups.

share|improve this answer
34  
If the user you're adding is the same user you're currently logged in, you will need to logout and log back in, in order to have the group update take effect. – Cris Holdorph Aug 22 '14 at 22:20
3  
please consider to add the login/logout action to the answer. – Sergio Aug 29 '14 at 14:51
30  
Instead of the you need to log out ... message, consider adding newgrp docker (as @grundic) posted below. This logs you into the docker group – Squidly Oct 28 '14 at 12:37
1  
Yeah, but every privileged process opens up potential for exploit. Is docker hooking that deep into the operating system to really mandate that level of privileges? – matt Jan 10 '15 at 14:24
6  
It's worth pointing out that this gives that user unrestricted, non-password protected root access. See details of the vulnerability here – Chris Foster Apr 22 '15 at 20:57

To run docker command without sudo, you need to add your user (who has root privilages) to docker group. For this run following command:

 sudo usermod -aG docker <user_name>

Now, restart the OS. This solution is well explained here with proper installation process.

share|improve this answer
    
after add user to group , run this command: sg group_name -c "bash" – madjardi Apr 9 at 2:12
5  
dont really need to restart the OS. Just logout and log in again. – binW May 17 at 9:50

protected by Community Dec 7 '14 at 8:04

Thank you for your interest in this question. Because it has attracted low-quality or spam answers that had to be removed, posting an answer now requires 10 reputation on this site (the association bonus does not count).

Would you like to answer one of these unanswered questions instead?

Not the answer you're looking for? Browse other questions tagged or ask your own question.