The error “permission denied while trying to connect to the Docker daemon socket” means your user does not have permission to access /var/run/docker.sock. This guide shows you how to fix it and understand the security implications.
Symptom
Running any docker command fails with:
docker ps
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.24/containers/json": dial unix /var/run/docker.sock: connect: permission denied
Or when building or running containers:
docker build -t myapp:latest .
Got permission denied...
docker run -it ubuntu bash
Got permission denied...
Why it happens
Ranked by likelihood:
- User is not in the docker group — By default, only root and users in the
dockergroup can access the Docker socket. - Rootless Docker mode is active — The Docker daemon runs as a non-root user, so the socket location and ownership are different.
- Socket ownership is incorrect —
/var/run/docker.sockis owned by root or another user, not your user or the docker group. - Snap installation of Docker — Snap’s confinement might prevent access to the socket.
- WSL2 (Windows Subsystem for Linux) quirks — Docker Desktop for Windows uses a different socket path or integration method.
- Socket file was deleted or recreated — After a system update or Docker restart, the socket might have wrong permissions.
Fix
1. User is not in the docker group
Add your user to the docker group:
sudo usermod -aG docker $USER
The aG flags mean “append to groups” so you keep your existing groups.
Apply the group change. Choose one:
Option A: Reload group membership (this session only):
newgrp docker
Option B: Log out and log back in (permanent):
logout
# Log back in
Verify it works:
docker ps
# Should return container list without "permission denied"
Check that you are in the docker group:
id -G
# Should include a number for 'docker' group (usually 999)
groups $USER
# Should show: user : user docker ...
2. Rootless Docker mode is active
Rootless Docker runs the daemon as a non-root user. Check if it is enabled:
docker run --rm -it alpine cat /proc/self/cgroup | grep docker
# If rootless, path includes /user.slice/...
Or check the Docker socket location:
# Standard: /var/run/docker.sock
# Rootless: ~/.docker/run/docker.sock
ls -la /var/run/docker.sock
ls -la ~/.docker/run/docker.sock
If using rootless Docker, your user should already have access since the daemon runs as your user. Verify:
docker ps
If you get a different permission error, the daemon might not be running. Start it:
# For rootless Docker
dockerd-rootless-setuptool.sh install
# Or start it manually
start-rootless
To switch back to standard Docker (with docker group):
# Uninstall rootless
dockerd-rootless-setuptool.sh uninstall
# Install standard Docker
# (Follow your distro's installation guide)
3. Socket ownership is incorrect
Check who owns the docker socket:
ls -la /var/run/docker.sock
# Output: srw-rw---- 1 root docker 0 Oct 26 11:00 /var/run/docker.sock
It should be owned by root:docker with 660 permissions. If it is not:
# Fix ownership
sudo chown root:docker /var/run/docker.sock
# Fix permissions
sudo chmod 660 /var/run/docker.sock
Verify:
ls -la /var/run/docker.sock
# Now shows: srw-rw---- 1 root docker ...
docker ps
If the socket is deleted (e.g., after system crash or update), restart Docker:
sudo systemctl restart docker
ls -la /var/run/docker.sock # Should reappear
4. Snap installation of Docker
Snap’s confinement can prevent Docker access. Check if Docker was installed via Snap:
which docker
# If it shows: /snap/bin/docker
# Then it's a Snap install
To allow Snap access to the Docker socket, use the docker interface:
snap connect docker:docker-daemon
Or remove the Snap version and install Docker officially:
snap remove docker
# Follow official Docker installation for your distro
# e.g., for Ubuntu:
sudo apt-get install docker.io
# Then add your user to docker group
sudo usermod -aG docker $USER
newgrp docker
5. WSL2 (Windows Subsystem for Linux) quirks
On Windows with WSL2, Docker Desktop for Windows uses a special integration. Check which Docker is running:
docker version
# If it connects to Docker Desktop, the context might be "desktop-linux"
Verify Docker is running:
docker ps
# If connection fails, Docker Desktop is not running on Windows
Start Docker Desktop (on Windows):
1. Open Docker Desktop from Start Menu
2. Wait for it to initialize (usually 30 seconds)
3. Go back to WSL2 terminal
Then verify:
docker ps
If you want to use Docker inside WSL2 (not Docker Desktop for Windows):
# Install Docker directly in WSL2
sudo apt-get install docker.io
# Add your user to docker group
sudo usermod -aG docker $USER
newgrp docker
# Start Docker daemon
sudo systemctl start docker
6. Socket file was deleted or recreated
If the socket was deleted (e.g., /var/run is cleaned up on some systems), restart Docker:
sudo systemctl restart docker
ls -la /var/run/docker.sock # Should reappear with correct permissions
Make sure the socket persists across reboots. Check the Docker systemd unit:
systemctl status docker
# Should show it's enabled and running
Enable Docker to start on boot:
sudo systemctl enable docker
Prevent it
-
Add users to the docker group during setup:
sudo usermod -aG docker myuser -
Make the socket permissions persistent. They are usually restored when Docker restarts, but you can also configure them in the Docker daemon config:
sudo mkdir -p /etc/docker cat <<'EOF' | sudo tee /etc/docker/daemon.json { "group": "docker" } EOF sudo systemctl restart docker -
Understand the security risk. Anyone in the docker group has root-equivalent access. Only add trusted users.
-
Use rootless Docker for additional isolation if you want to give users Docker access without root-equivalent privileges:
dockerd-rootless-setuptool.sh install -
Check socket ownership after system updates:
ls -la /var/run/docker.sock
Security Note: Docker Group = Root
Adding a user to the docker group effectively gives them root access. Here is why:
# Any docker group member can run containers as root
docker run -it --rm -v /:/mnt ubuntu bash
# Inside the container, /mnt points to the host filesystem
# And you are running as root inside the container
# So you can modify anything on the host
# Or mount the host's root filesystem
docker run -it --rm -v /proc:/host/proc ubuntu bash
# Access host processes and kernel state
# Or escape to the host via volumes
docker run -it --rm -v /root/.ssh:/tmp ubuntu bash
# Access sensitive files
Best practices:
1. Only add users you fully trust to the docker group.
2. Use rootless Docker if you want to restrict access.
3. Use SELinux or AppArmor profiles to further restrict container capabilities.
4. In multi-user systems, prefer centralized Docker access (e.g., via a CI/CD system that manages permissions).
FAQ
How do I fix ‘permission denied while trying to connect to the Docker daemon socket’?
Add your user to the docker group: sudo usermod -aG docker $USER, then logout and login again or run newgrp docker. Warning: this gives the user root-equivalent permissions.
What does ‘docker group = root’ mean?
Anyone in the docker group can run containers with root privileges. It’s equivalent to sudo access. Only add trusted users to the docker group.
Why does Docker require root access?
Docker containers use Linux namespaces and cgroups, which require root. Rootless Docker mode (non-root daemon) exists but is not the default.
How do I check if my user is in the docker group?
Run groups $USER or id -G. If you see ‘docker’ in the list, you’re in the group. Verify with docker ps (should not ask for sudo).
How this guide was verified
Written by hand from the official documentation, every command re-checked, and reviewed a second time before publishing. Last reviewed on .
Official sources read for this article

