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.
-
Edit the rc.local file by adding the following line:
#!/bin/bash chmod 666 /var/run/docker.sock
-
Make rc.local Executable:
sudo chmod +x /etc/rc.local
-
Enable and start the rc-local service to ensure it runs during startup.
-
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.