How to Fix Docker Permission Denied on Ubuntu 22.04
The Root Cause
This error occurs because the Docker daemon, which manages containers, runs as the root user and listens on a Unix socket (/var/run/docker.sock). By default, only the root user and members of the docker group have read/write access to this socket, preventing unprivileged users from executing Docker commands directly without sudo.
Quick Fix (CLI)
# 1. Add your current user to the 'docker' group
sudo usermod -aG docker $USER
# 2. Apply the new group membership (choose one):
# a) Log out and log back in (recommended for full session refresh).
# b) For immediate effect in the current terminal session, use 'newgrp docker'.
# Note: This only affects the current shell and child processes.
newgrp docker
# 3. Restart the Docker daemon (optional, but good practice to ensure all permissions are reloaded)
sudo systemctl restart docker
Configuration Check
This specific “Permission Denied” issue is a system-level user group management problem, not a Docker daemon configuration file (e.g., /etc/docker/daemon.json) or Dockerfile issue. The sudo usermod -aG docker $USER command modifies the system’s group configuration.
-
File to check:
/etc/group -
Lines to change (conceptually, as
usermodhandles this): Locate the line starting withdocker:. After applying the fix, your username should be appended to this line.Example before fix (if user
devopsis not in group):docker:x:999:Example after fix (user
devopsadded):docker:x:999:devops
Verification
# Run a basic Docker command without 'sudo' to confirm permissions
docker run hello-world
# You should see output similar to:
# Hello from Docker!
# This message shows that your installation appears to be working correctly.