Low Orbit Flux Logo 2 D

Got permission denied while trying to connect to the Docker daemon socket

If you are just getting started with Docker there is a good chance you have come across this error message. “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.40/containers/json: dial unix /var/run/docker.sock: connect: permission denied” It basically means that you don’t have the required permissions to connect to the docker daemon. You will need the correct permissions to run any docker commands. It does confirm that the Docker daemon is running because if it wasn’t it wouldn’t be able to deny you access. It would just say that you can’t connect.

This issue will usually pop up as soon as you try to run any Docker related commands such as docker ps.

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.40/containers/json: dial unix /var/run/docker.sock: connect: permission denied

The Fix

There are a few different ways you could go about fixing this.

Option 1: Sudo

You can run Docker commands with sudo like this:


sudo docker ps

Option 2: Become Root

If you have the rights to run “sudo su -“ you can run Docker commands as root like this:


sudo su -   # sudo to root
docker ps   # directly run command

If you have the root password, you can run Docker commands as root like this:


su -        # change to root user
docker ps   # directly run command

Option 3: How To Grant Permissions To A Non-root User

Run these two commands to create a docker group and add your current user to it.


sudo groupadd docker
sudo usermod -aG docker $USER

If you had already run some docker commands as root you will likely see additional error after adding the docker group. You can fix these by adjusting the permissions on the “.docker” directory recursively.


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

Verify that it works:


docker run hello-world

Video: “Got permission denied while trying to connect to the Docker daemon socket”

References

Official Docker Documentation Source