How To Execute Docker without using sudo privilege on Ubuntu 20.04
In this tutorial you will be shown how to configure Ubuntu 20.04 to execute Docker without using sudo. By default, you have to run docker commands with sudo privilege or by a user in the docker group. This tutorial will show you how to bypass that.
To test your privileges to confirm you cannot run Docker without sudo type in docker run hello-word. You should get the following message and if should move forward with the tutorial.
$ docker run hello-world Got permission denied while trying to connect to the Docker daemon socket at unix:///var/run/docker. sock: Get http://%2Fvar%2Frun%2Fdocker.sock/v1.27/containers/json: dial unix /var/run/docker.sock: connect: permission denied
Lets Get Started
- SSH into your Ubuntu 20.04 server.
- Create new group. This command will likely fail as group maybe already exist, but let’s run it anyways.
sudo groupadd docker
3. Now we will add the current logged in user to the docker group
sudo gpasswd -a $USER docker
4. Lets restart the group shell by running the following command. A reboot would work as well.
newgrp docker
5. Now if your run the following command docker run hello-world you should see a successful message instead of an error that you do not have permissions.
docker run hello-world Unable to find image 'hello-world:latest' locally latest: Pulling from library/hello-world ca4f61b1923c: Pull complete Digest: sha256:97ce6fa4b6cdc0790cda65fe7290b74cfebd9fa0c9b8c38e979330d547d22ce1 Status: Downloaded newer image for hello-world:latest Hello from Docker! This message shows that your installation appears to be working correctly.
Do you need to know how to install Docker? Would you like to be notified of when I create a new post you can subscribe to my blog alert.
Discover more from Patrick Domingues
Subscribe to get the latest posts sent to your email.