When working with Docker in Linux, you may find yourself using sudo before every Docker command. This is because the docker daemon binds to a Unix socket (which by default is owned by the root user) rather than a TCP port. Thus the reason for always needing to use sudo.

A good way to avoid this is to create a docker group and add your user to it. You can do this following the steps below.

1. Change the login session’s owner to root. If you are unable to do this the root user password probably needs to be unlocked – Unlock root user password Linux

$ su -

2. Create the docker group

$ groupadd docker

3. Add your user to this group

$ usermod -aG docker myuser

4. Change the login session’s owner back to original user

$ su myuser

5. Restart Docker to see the change take effect

$ sudo service docker restart

Leave a Reply

Create a Docker group Linux