Docker
Oct 8, 2025 4 min read

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

bash
Got permission denied while trying to connect to the Docker daemon socket at unix:///var/run/docker.sock

Root 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

bash
sudo groupadd docker || true
sudo usermod -aG docker $USER
newgrp docker

Log out and back in (or run `newgrp docker`) so the new group membership is loaded.

Verify

bash
docker run --rm hello-world

Never `chmod 777 /var/run/docker.sock`. That gives every local user root-equivalent access through the daemon.

Frequently asked questions

Related fixes

Weekly digest

One DevOps fix in your inbox each week

Short, practical, no fluff. Real errors, real fixes — straight from production postmortems.