How to solve docker: Got permission denied Error

You tried to run a Docker command without sudo or in other words, as a non root user. This has returned an error which is similar to the following:

docker: Got permission denied while trying to connect to the Docker daemon socket at XX /var/run/docker.sock: connect: permission denied.

This ‘docker got permission denied‘ error has been returned because you do not have sufficient privileges on the file /var/run/docker.sock .

Since the Unix socket belongs to the user root, what you can do is obviously to run the command as sudo since you will then have all root privileges.

What you can also do in order to run the command as a non root user is to add a docker group and then add your user to it. This can be done using the command :

sudo groupadd docker

Read: How to run and manage a Docker container on Linux Ubuntu/Debian

After having added the docker group and in order to get group policies applied correctly, you would need to exit and log in again.

To validate the changes to groups, you also have the possibility to run the command below in case you are on Ubuntu or Linux in general :

newgrp docker

Now to check if, without root, docker can be run, invoke the command below:

docker run hello-world

If you still get an error, you may need to reboot by running the command :

reboot

Read: How to fix Docker error mkdir [folder]: read-only file system

Source : For more details on this, you may want to refer to the official documentation of Docker.


If you like the content, we would appreciate your support by buying us a coffee. Thank you so much for your visit and support.

 

Marianne elanotta

Marianne is a graduate in communication technologies and enjoys sharing the latest technological advances across various fields. Her programming skills include Java OO and Javascript, and she prefers working on open-source operating systems. In her free time, she enjoys playing chess and computer games with her two children.

Leave a Reply