docker permission denied /var/run/docker.sock — how to fix

# Add your user to the docker group
sudo usermod -aG docker $USER

# Apply the new group (or log out and back in)
newgrp docker

# Verify
docker run --rm hello-world
Got permission denied while trying to connect to the Docker daemon socket at
unix:///var/run/docker.sock: Post "http://%2Fvar%2Frun%2Fdocker.sock/v1.24/containers/create":
dial unix /var/run/docker.sock: connect: permission denied

Your user does not have permission to access the Docker socket. Adding yourself to the docker group grants access without sudo.

Run with sudo (quick but not recommended)

sudo docker run --rm hello-world

Check the docker group exists

grep docker /etc/group
# If missing, create it:
sudo groupadd docker

Rootless Docker — run Docker without root

Rootless mode runs the Docker daemon as a non-root user, improving security.

# Install rootless Docker (Ubuntu/Debian)
dockerd-rootless-setuptool.sh install

# Add to your shell profile
export PATH=/usr/bin:$PATH
export DOCKER_HOST=unix://$XDG_RUNTIME_DIR/docker.sock