Running Docker commands without sudo - NidhiSingh0068/Docker-Content Wiki
By default, we can only use the docker commands with root privileges. Ubuntu requires the use of the sudo prefix. For example, if you try to run a hello-world container, the output displays permission was denied.
To bypass typing sudo every time. Adding the user to the docker group grants privileges equivalent to root.
- Create the docker group with command.
sudo groupadd docker
- Now, type the following command (making sure to replace [user] with your username):
sudo usermod -aG docker [user]
- Enable the new settings with:
su - [user]
- Lastly, check to confirm the user is now a part of the docker group by running:
- To apply these changes, need to reload the shell in order to make the changes take effect. Often need to reboot shell.
Now, setup is done to run docker commands without doing sudo everytime, i.e user is now added to the docker group.
Let's test the docker command without sudo.