Skip to content

Instantly share code, notes, and snippets.

@RishikeshDarandale
Last active November 28, 2015 11:30
Show Gist options
  • Save RishikeshDarandale/d116fb0e43be160ef76f to your computer and use it in GitHub Desktop.
Save RishikeshDarandale/d116fb0e43be160ef76f to your computer and use it in GitHub Desktop.
How can I use docker without sudo?
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 and up use docker.io instead:
sudo service docker.io restart
Either do a newgrp docker or log out/in to activate the changes to groups.
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.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment