Tuesday, April 19, 2016

Docker Optional Configurations

Adding user to docker group

1. If you have not configured anything extra, then docker needs root to work. By default, the docker daemon listens on a local Unix socket called 'docker.sock' in /var/run  which is owned by the user root.

If you do 
# ls /run -l

Notice the docker.sock with 's' at the start of the line telling it’s a socket. We can see it is owned by the root but the group owner is the group called docker. So the good thing is instead of giving root permission to the user we can just add that user to the docker group.

2. Now let's get out from root user. So if you are in root, hit
# exit
Then , Check the docker group exists or not
# cat /etc/group

At the end we see our docker group with no members.

3. Now to add user to the docker group 
# sudo usermod -aG docker usapkota 
Replace 'usapkota' with your username 

4. Check
# cat /etc/group

Notice the user in docker group.

5. Logout and log back in. Try running docker command from user, to see if it is working or not.  If you still get this error 
'Cannot connect to the Docker daemon. Is 'docker daemon' running on this host?'
Then reboot your machine with, 

# sudo reboot

6. Enter docker run command from user to see it works,
 # docker run hello-world 

7. Great!! Now you can run docker without slapping sudo. 

No comments:

Post a Comment