https://docs.docker.com/installation/ubuntulinux/#giving-non-root-access
https://ubuntuincident.wordpress.com/2014/01/10/docker/
Create a docker group
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 other users can access it with sudo
. For this reason, docker
daemon always runs as the root
user.
To avoid having to use sudo
when you use the docker
command, create a Unix group called docker
and add users to it. When the docker
daemon starts, it makes the ownership of the Unix socket read/writable by the docker
group.
Warning: The
docker
group is equivalent to theroot
user; For details on how this impacts security in your system, see Docker Daemon Attack Surface for details.
To create the docker
group and add your user:
Log into Ubuntu as a user with
sudo
privileges.This procedure assumes you log in as the
ubuntu
user.Create the
docker
group and add your user.$ sudo usermod -aG docker ubuntu
Log out and log back in.
This ensures your user is running with the correct permissions.
Verify your work by running
docker
withoutsudo
.$ docker run hello-world
Execute docker as non-root
As you noticed, docker
must be executed with sudo
. If you want to execute it with your non-root account, here is what to do:
1
2
3
4
5
6
|
# create the 'docker' group
$
sudo
groupadd docker
# probably it already exists
# add your user to the 'docker' group
$
sudo
gpasswd -a USER docker
# replace USER with your user name
# restart the service
$
sudo
service docker restart
|
You will have to log out and log back in to make the group settings active on your account. After that you can launch docker
without sudo
:
1
2
3
4
5
6
7
|
$ docker images
REPOSITORY TAG ID CREATED SIZE
ubuntu 12.04 8dbd9e392a96 4 months ago 131.5 MB (virtual 131.5 MB)
ubuntu 12.10 b750fe79269d 5 months ago 24.65 kB (virtual 180.1 MB)
ubuntu latest 8dbd9e392a96 4 months ago 131.5 MB (virtual 131.5 MB)
ubuntu precise 8dbd9e392a96 4 months ago 131.5 MB (virtual 131.5 MB)
ubuntu quantal b750fe79269d 5 months ago 24.65 kB (virtual 180.1 MB)
|