Running Docker Without Sudo on Linux

After installing Docker on Linux, you may get a permission denied message as shown below when you try to run your first docker command:

docker: Got permission denied while trying to connect to the Docker daemon socket at unix:///var/run/docker.sock: Post http://%2Fvar%2Frun%2Fdocker.sock/v1.24/containers/create: dial unix /var/run/docker.sock: connect: permission denied.
See 'docker run --help'.

You can solve this problem by running Docker with root privileges (using sudo). However, by following these simple steps given below, you can run docker without root privileges.

Running Docker Without Sudo on Linux
 Step 01:

Create a new user group if not created automatically by docker.

sudo groupadd docker


Step 02:

Add the current user to the docker user group.

sudo usermod -aG docker $USER


Step 03:

Run the following command to apply the changes. If it doesn't help, restart your computer.

newgrp docker


Step 04:

Run your docker command to test if it works without root privileges. The hello world command is given below for testing purposes.

docker run hello-world


Step 05:

In case if you previously ran Docker as root, you may get an error like this:

WARNING: Error loading config file: /home/user/.docker/config.json -
stat /home/user/.docker/config.json: permission denied

Run the following command to change the ownership of the docker config folder.

sudo chown "$USER":"$USER" /home/"$USER"/.docker -R
sudo chmod g+rwx "$HOME/.docker" -R

I hope these steps help you resolve the problem. Feel free to comment below if you have any issues related to this solution.

Previous
Next Post »

Contact Form

Name

Email *

Message *