Problem scenario
You try to run a Docker command, but you get this error: 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.29/containers/json?all=1: dial unix /var/run/docker.sock: connect: permission denied
What should you do?
Solution
Have you added the user who was trying to execute the command to the "docker" group?
This command would add the user jdoe to the "docker" group:sudo usermod -aG docker jdoe
If you ran the above command as the jdoe user, log out and log back in.
It is not advisable to run "docker" commands with "sudo " before them. In rare cases it may be necessary to use it to get the "docker" command to work.
For troubleshooting similar errors you may want to click on one of the following:
- Why am I getting this error "Cannot connect to the Docker daemon at unix:///var/run/docker.sock."?
- How Do You Troubleshoot This Error "…docker.sock: read:: connection reset by peer"?
- How Do You Troubleshoot "Permission Denied" When Trying to Use "Docker Login" to Authenticate with a Docker Registry?