Fix Docker "permission denied while trying to connect to the Docker daemon socket"
The classic Docker socket permission error and the safe way to fix it without chmod 777.
Problem
Got permission denied while trying to connect to the Docker daemon socket at unix:///var/run/docker.sockRoot cause
The Docker daemon socket is owned by `root:docker`. Your user is not in the `docker` group, so the kernel rejects the connection.
Solution
Add your user to the docker group
sudo groupadd docker || true
sudo usermod -aG docker $USER
newgrp dockerLog out and back in (or run `newgrp docker`) so the new group membership is loaded.
Verify
docker run --rm hello-worldNever `chmod 777 /var/run/docker.sock`. That gives every local user root-equivalent access through the daemon.
Frequently asked questions
Related fixes
Docker
4 minFix Docker "no space left on device"
Reclaim disk used by dangling images, stopped containers, build cache and volumes.
#disk#cleanup#build-cache
Docker
3 minFix docker-compose "network ... not found"
Why Docker Compose can't find an external network and how to declare or create it.
#compose#networks
Weekly digest
One DevOps fix in your inbox each week
Short, practical, no fluff. Real errors, real fixes — straight from production postmortems.