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 ‘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

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

As a graduate in communication technologies, Marianne likes to share the latest technological advances in various fields. She likes to program in Java OO and Javascript and prefers to work on Open source operating systems. She likes to play chess and computer games in her spare time along with her 2 kids.

Leave a Reply

Close Menu