Docker: permission denied while connecting to daemon socket
Fix Linux Docker daemon permission errors without needing to run sudo docker on every command.
Error Message
docker: 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.47/containers/json":
dial unix /var/run/docker.sock: connect: permission denied.Symptoms
- Running any docker command (
docker ps,docker run) fails with permission denied. - Prepending
sudo docker psworks, but requiringsudoon every command breaks VS Code containers, Docker Compose, and developer tooling.
Why It Happens
The Docker daemon always runs as the root superuser and communicates over the Unix domain socket /var/run/docker.sock. By default, this socket file is owned by root:docker with rw-rw---- permissions.
If your Linux user account is not an active member of the docker system group, the operating system blocks unprivileged access to the socket.
Quick Fix (1-Liner)
sudo usermod -aG docker $USER && newgrp dockerStep-by-Step Fix
Docker: Bind for 0.0.0.0:PORT failed: port is already allocated
Fix port conflict errors in Docker and Docker Compose when another container or host service is already listening on the requested port.
Docker: Container exits immediately with code 0 or 1
Fix containers that terminate immediately upon startup (Exited (0) or Exited (1)) due to foreground process termination, syntax errors, or missing entrypoints.