[Solved] Permission Denied while trying to connect to the Docker Daemon Socket at unix:///var/run/docker.sock Error

We can solve this by changing the permission of the Docker socket file using the command:

sudo chmod 666 /var/run/docker.sock

But it is a temporary change and will revert to the default permission after a system reboot.

It happens because the Docker socket file is inside the /var/run directory, which is mounted as a temporary filesystem (tmpfs).

Also, the Docker daemon generates the socket file with specific permissions during startup.

Since tmpfs stores its contents in RAM, any files or directories within it are wiped and regenerated every time the system boots.

Solution

We can use the rc.local file to run the command every time the system reboot.

  1. Edit the rc.local file by adding the following line:

    #!/bin/bash
    chmod 666 /var/run/docker.sock
    
  2. Make rc.local Executable:

    sudo chmod +x /etc/rc.local
    
  3. Enable and start the rc-local service to ensure it runs during startup.

  4. Reboot your system, and the script will execute automatically, and it will change the Docker socket file’s permission.

Security Consideration

In the context of file permissions, “666” means that anyone can read from or write to the file. This is very permissive and can be a security risk.

If you’re working with Docker in a professional or sensitive environment, it’s a good idea to consult with a security tem or follow best practices for securing Docker.