[Fixed] How to fix "dial unix /var/run/docker.sock: connect: permission denied" when group permissions seem correct? – Docker

Photo of author
Written By M Ibrahim
boot2docker ubuntu-18.04

Quick Fix: Run the following command to set proper permissions on the Docker socket:

sudo setfacl –modify user::rw /var/run/docker.sock

The Problem:

An issue has arisen while using Docker on Ubuntu 18.04 after an update. When trying to run Docker commands, it throws the error "Got permission denied while trying to connect to the Docker daemon socket at unix:///var/run/docker.sock: Post http://%2Fvar%2Frun%2Fdocker.sock/v1.35/containers/create: dial unix /var/run/docker.sock: connect: permission denied.". The permissions for the /var/run/docker.sock file seem correct, as it is set to srw-rw—- for the docker group, and the current user is a member of the group. The issue persists after restarting the Docker service and updating the Docker version.

The Solutions:

Solution 1: Using setfacl to Modify Permissions

\n

Execute the following command to modify permissions for the Docker socket using setfacl:

sudo setfacl --modify user:<user name or ID>:rw /var/run/docker.sock

\n

Enter your user name or ID in place of "<user name or ID>". This command will modify the permissions on the Docker socket to grant read and write access to the specified user.

Solution 3: Give the correct permission to docker.sock file

To fix the error, you need to ensure that the docker.sock file has the correct permissions. You can do this by running the following command in a terminal window:

sudo chmod 666 /var/run/docker.sock

This command will change the file permissions so that all users can read and write the file.

Solution 4: Fix permissions for Docker group

You can resolve the “dial unix /var/run/docker.sock: connect: permission denied” issue by ensuring that the Docker group has the necessary permissions. Execute the following commands:

  1. Add the docker group:

    sudo addgroup --system docker
    
  2. Add the current user to the docker group:

    sudo adduser $USER docker
    
  3. Switch to the docker group:

    newgrp docker
    

These steps should grant your user the required permissions to access the Docker daemon.

Solution 5: Fix the permissions on the Docker socket

If the group permissions seem correct, you can try fixing the permissions on the Docker socket itself. To do this, run the following command as root:

sudo setfacl --modify user:$USER:rw /var/run/docker.sock

This command will add your user to the list of users who have read and write permissions to the Docker socket. Once you have done this, you should be able to run Docker commands without any problems.