Docker 101 : Troubleshooting - Got permission denied while trying to connect to the Docker daemon ... -



After installing docker, we try to run some commands like the below command that list the containers:


After running the command, we get the below error message, because we can't connect to the docker local Unix socket: "unix:///var/run/docker.sock". 

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

A socket is a communication endpoint between two programs running locally or over the network.

The docker command line interface - CLI - uses the local Unix socket - /var/run/docker.sock - to communicate with the docker daemon.
We communicate with the docker daemon when we use the CLI interface, for example when we type in "docker ps" to list our containers.

To avoid that error, we would need to add our "username" to the group of users - docker - that have permissions to connect to the docker daemon socket.

We could do that using the below command:


Remark:

We could replace our username with the command "$(whoami)", which outputs the username we are logged in as.

If for any reason the group does not exist, we could create it using the below command:


We might also need to run the below command to change the current Group ID - we are logged in as to the "docker" group ID:

Comments

Leave as a comment:

Archive