How To Fix ‘Got permission denied while trying to connect to the Docker daemon socket’ Error In Ubuntu
Encountering “Permission denied” when using Docker on Ubuntu? Here’s how to fix it. We have covered the solution for the following error that you sometime encounter while using Docker in Ubuntu:
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.39/containers/json: dial unix /var/run/docker.sock: connect: permission denied
How To Fix ‘Got permission denied while trying to connect to the Docker daemon socket’ Error In Ubuntu
1. Run Docker commands without sudo (recommended):
Create the docker group:
sudo groupadd docker
Add your user to the group:
sudo usermod -aG docker $USER
Now you need to log out and log back in for changes to take effect.
2. Run Docker commands with sudo (alternative):
sudo docker
Note: Running Docker with sudo grants full root privileges, which can be less secure. It’s generally recommended to use the first method and add your user to the docker group.
If you’re still encountering issues, restart your system.
For advanced troubleshooting, consult Docker’s official documentation.