How to run docker commands without sudo
Photo by Gabriel Heinzer on Unsplash

How to run docker commands without sudo

I will use Ubuntu 22.04 to show you how to run Docker commands without sudo, but the process is the same in most Linux distributions.

Let's run hello-world image:

As you noticed, you have to run docker with and you will get permissions denied if you will try to run without .

That because 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 only access it using sudo. The docker daemon always runs as the root user.

If you don’t want 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.

  • Add the docker group (it might already exist):

  • Add the connected user “$USER” to the docker group:

This adds the current user to the docker group. If you want to add another user, change the username to match it.

  • Either do a newgrp docker or log out/in to activate the changes to groups:

  • Run docker run hello-world command to test it:

Thank you! You saved my day. :)

Like
Reply

To view or add a comment, sign in

Insights from the community

Others also viewed

Explore topics