Permission denied problems with Docker on Linux are frequently associated with files or system services permissions.

Why “permission denied” errors occur with docker-compose#

A common problem when performing docker-Compose for the first time is the lack of permission in the docker.sock file:

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

How to solve “permission denied” with docker-compose#

You need to perform some steps to understand if the service running and then configure the user that run docker commands.

Checking if the docker service is running#

Start by checking the Docker service status:

sudo systemctl status docker

If it is not active - as shown in the following image, use the Start or Restart command to start it:

Docker status
Docker status

sudo systemctl start docker

Now test to make sure the service is running:

sudo docker run hello-world

Adding the user account to the docker group#

Now you need to add the user you are using to the group that has permission to record in the privileged docker files.

Start by creating the docker group - note that it can already exist in the system, this is not a problem:

sudo groupadd docker

After ensuring the creation of the group, add your user to it

sudo usermod -aG docker $USER

Finally, restart the system and run the docker-compose commands that were generating the permission denied error.

Final considerations#

Permission denied errors occur not only with Docker services in your system, probably you can follow these steps as a recipe to understand other system services with similar errors.