Cloud Explainers

How to Fix Docker 'Permission Denied' on docker.sock

Docker6 min videoPublished Nov 14, 2026

docker ps says 'permission denied while trying to connect to the docker API at unix:///var/run/docker.sock' (older Docker: 'the Docker daemon socket'). On a real Ubuntu 24.04 PC with Docker we show why: the socket only lets in root and the docker group. We add the user with usermod -aG, see why it still fails until you log in again, tell 'permission denied' from 'is the docker daemon running?', and show what usermod -G without -a and chmod 666 really do.

Permission denied on docker.sock

You typed docker ps, and got: permission denied, while trying to connect to the docker API. Put sudo in front, which runs it as the administrator, root, and the same command lists the running containers: here, a music school's booking page. So Docker is fine. You just aren't allowed to talk to it. One popular fix lets every account on the PC talk to it, until the next reboot. We'll see which.

ben@office-pc: Ben's terminal
docker ps --format '{{.Names}}  {{.Image}}  {{.Status}}'permission denied while trying to connect to the docker API at unix:///var/run/docker.sock
ben@office-pc: Ben's terminal
sudo docker ps --format '{{.Names}}  {{.Image}}  {{.Status}}'[sudo] password for ben:
bookings  nginx:alpine  Up 2 seconds

What docker.sock is

So who decides? The docker command is only a messenger. The work is done by the Docker daemon, a background service that runs as root. The two talk through one special file, docker dot sock. Think of that file as a staff-only door, with a keycard list: root, and the docker group. sudo runs the command as root, so it walks in. Ben, new in the school's office, is not on the list.

One door between you and Docker: diagram of Ben's docker ps, sudo docker ps, docker.sock, Docker daemon, Containers

The list is printed on the file itself. ls dash l on slash var slash run slash docker dot sock shows it in ten characters. The s means socket. Then read and write for the owner, read and write for the group, and nothing for everyone else. The owner is root, the group is docker.

The door's keycard list, in ls -l: diagram of srw-rw---- root docker, s = type, rw- = owner, rw- = group, --- = everyone else, root = owner, docker = group, Not root, not in docker: denied

The fix: the docker group

So the usual fix: put Ben on the list. First, id, which shows who you are, lists Ben's groups: ben and sudo. No docker. So Ben runs user mod with dash a capital G, docker, ben: capital G names a group, and dash a means add it to the ones he has. It prints nothing, which means it worked. Guess first: does his docker ps work now? No. The same error, word for word.

ben@office-pc: Ben's terminal
iduid=1001(ben) gid=1001(ben) groups=1001(ben),27(sudo)
ben@office-pc: Ben's terminal
sudo usermod -aG docker ben
ben@office-pc: Ben's terminal
docker ps --format '{{.Names}}  {{.Image}}  {{.Status}}'permission denied while trying to connect to the docker API at unix:///var/run/docker.sock

Why it still fails: log in again

Why? Ask id about Ben by name, and docker is there. getent, which reads the group list, says so too: ana, ben. But plain id, about this terminal, still says no. Linux gives a program its groups when it starts, and Ben's shell started before the change. Back at the staff door: the list was updated, but Ben's keycard was printed when he logged in this morning.

ben@office-pc: Ben's terminal
id benuid=1001(ben) gid=1001(ben) groups=1001(ben),27(sudo),102(docker)
ben@office-pc: Ben's terminal
getent group dockerdocker:x:102:ana,ben
ben@office-pc: Ben's terminal
iduid=1001(ben) gid=1001(ben) groups=1001(ben),27(sudo)

So get a new keycard. new group docker starts a shell with the group, and docker ps works in it, but only in that one shell. The real fix is to log out and back in. Now plain id lists docker, and docker ps works without sudo.

ben@office-pc: Ben's terminal
newgrp docker
ben@office-pc: Ben's terminal
docker ps --format '{{.Names}}  {{.Image}}  {{.Status}}'bookings  nginx:alpine  Up 1 second
ben@office-pc: Ben's terminal
exitexit
ben@office-pc: Ben's terminal
iduid=1001(ben) gid=1001(ben) groups=1001(ben),27(sudo),102(docker)
ben@office-pc: Ben's terminal
docker ps --format '{{.Names}}  {{.Image}}  {{.Status}}'bookings  nginx:alpine  Up 3 seconds

Docker's own setup page agrees, and adds one detail: on a virtual machine, you may need to restart it before the group takes effect.

Why it still fails: log in again: browser screenshot of log out and back in

Denied, or not running?

Read the error before you fix it, though. Earlier that day, Ana stopped Docker for an update, with systemctl, the tool that controls background services. Guess first: what does Ben's plain docker ps say then? Still permission denied. Linux checks the socket file's permissions before anything reaches Docker, so Ben never finds out nobody is home. Only with sudo does the real problem show: cannot connect. Is the docker daemon running?

ben@office-pc: Ben's terminal
sudo systemctl stop docker docker.socket[sudo] password for ana:
ben@office-pc: Ben's terminal
docker ps --format '{{.Names}}  {{.Image}}  {{.Status}}'permission denied while trying to connect to the docker API at unix:///var/run/docker.sock
ben@office-pc: Ben's terminal
sudo docker ps --format '{{.Names}}  {{.Image}}  {{.Status}}'Cannot connect to the Docker daemon at unix:///var/run/docker.sock. Is the docker daemon running?

So match the message to the fix. Permission denied: the group. Older Docker versions, like 24, word it as the Docker daemon socket, with connect, permission denied at the end. Same cause. Is the docker daemon running: start it, with systemctl start docker.

Which message, which fix: comparison table of The message says vs The fix, Docker 29, Docker 24, Stopped

Two fixes that backfire

Now the two fixes that backfire. The first is a missing letter. Ana adds a new helper, Eli, who is an admin: his groups include sudo. She types user mod dash capital G docker, but forgets the dash a. Without it, the list is replaced, not added to. Eli is in docker, and no longer an admin. Adding sudo back with dash a repairs it.

ana@office-pc: Ana's terminal
id eliuid=1003(eli) gid=1003(eli) groups=1003(eli),27(sudo)
ana@office-pc: Ana's terminal
sudo usermod -G docker eli
ana@office-pc: Ana's terminal
id eliuid=1003(eli) gid=1003(eli) groups=1003(eli),102(docker)
ana@office-pc: Ana's terminal
sudo usermod -aG sudo eli
ana@office-pc: Ana's terminal
id eliuid=1003(eli) gid=1003(eli) groups=1003(eli),27(sudo),102(docker)

The second is the popular one. C H mod changes a file's permissions, and six six six means read and write for owner, group, and everyone else. She runs it on the socket, and the last group of letters now says read and write for all. The staff door is propped open.

ana@office-pc: Ana's terminal
sudo chmod 666 /var/run/docker.sock
ana@office-pc: Ana's terminal
ls -l /var/run/docker.socksrw-rw-rw- 1 root docker 0 Nov 14 14:52 /var/run/docker.sock

Cara has a part-time account: no sudo, not in the docker group. Denied before. After the C H mod, she sees the booking page's container, while sudo still refuses her. Docker is open to every account on the PC.

cara@office-pc: Cara's terminal
docker ps --format '{{.Names}}  {{.Image}}  {{.Status}}'permission denied while trying to connect to the docker API at unix:///var/run/docker.sock
cara@office-pc: Cara's terminal
docker ps --format '{{.Names}}  {{.Image}}  {{.Status}}'bookings  nginx:alpine  Up 4 seconds
cara@office-pc: Cara's terminal
sudo ls /root[sudo] password for cara:
cara is not in the sudoers file.

And it doesn't even last. Ana reboots the PC. The socket is back to read and write for root and the group only, and Cara is denied again. systemd, the service manager that starts everything at boot, makes the socket fresh at every start, and its settings say: mode zero six six zero, group docker. So C H mod six six six is a hole that closes at the next reboot, and someone types it again.

ana@office-pc: Ana's terminal
sudo reboot
ana@office-pc: Ana's terminal
ls -l /var/run/docker.socksrw-rw---- 1 root docker 0 Nov 14 14:52 /var/run/docker.sock
ana@office-pc: Ana's terminal
systemctl cat docker.socket# /usr/lib/systemd/system/docker.socket
[Unit]
Description=Docker Socket for the API

[Socket]
ListenStream=/run/docker.sock
SocketMode=0660
SocketUser=root
SocketGroup=docker

[Install]
WantedBy=sockets.target

Who should be in the group

So who belongs in the docker group? Docker's own page warns: the docker group grants root-level privileges. The daemon runs as root, and it starts whatever a group member asks for, with full control of the PC. So treat the docker group like sudo: add only people you'd trust as an admin.

Who should be in the group: browser screenshot from the video

Recap

So, permission denied on docker dot sock: join the group with user mod dash a G, then log out and back in. Cannot connect means Docker isn't running. Never C H mod six six six, which opens it to everyone, and add only people you'd trust with root.

Permission denied on docker.sock: diagram of Join the group, Log out and back in, Cannot connect?, Never chmod 666, The group = root

If Docker answers you now without sudo, a like helps the next stuck beginner find this, and subscribing brings more fixes run on real machines.

Every error in this video came from a real Ubuntu PC with Docker, and every command and the lab files are linked in the description. Thanks for watching Cloud Explainers.

Sources

Demos: a container on our own Mac standing in for a music school's office PC; the school and its staff are made up. Every error and the reboot were real. Watch the full video on YouTube.

More videos

Networking11 min

Every Networking Term a Beginner Needs in 12 Minutes

Git7 min

How to Fix Git 'Updates Were Rejected' When You Push

Linux7 min

How to Fix nginx 502 Bad Gateway Errors on Linux

Linux8 min

How to Fix Linux apt 'Could Not Get Lock' Errors (Ubuntu)

Networking9 min

How Email Works on the Internet (SMTP) in 10 Minutes

Python8 min

The Python Roadmap for Beginners

Go (Golang)21 min

Golang REST API with Gin: Full Tutorial for Beginners

Networking10 min

How a WireGuard VPN Network Works

Linux9 min

Linux Makefiles Will Finally Make Sense After This

Auth (OAuth, JWT)9 min

SAML vs OAuth vs OpenID Connect: What's the Difference?

Python7 min

How to Fix Python cron Jobs That Never Run

Linux22 min

Linux Bash Scripting: Full Tutorial for Beginners

Networking10 min

How PXE Network Boot Works

Active Directory9 min

How Active Directory Works

Linux10 min

How to Fix a Linux systemd Service That Won't Start

Linux9 min

Linux Logs: syslog vs journald

Auth (OAuth, JWT)9 min

JWT vs Session Cookies: Which One Should You Use?

Docker10 min

Docker vs Docker Compose: Which One Should You Use?

Docker9 min

How to Fix Docker Compose Containers That Can't Talk to Each Other

Django (Python web framework)22 min

Django Full Tutorial for Beginners

Linux9 min

How Linux systemd Works

Networking8 min

How to Fix 'Windows Cannot Access' Network Share Errors (SMB)

APIs10 min

REST vs gRPC: Which One Should You Use?

Certificates & PKI (ADCS)9 min

How to Fix SSL Certificate Chain Errors (Missing Intermediate)

Python9 min

Every Python Concept for Beginners in 10 Minutes

Databases & SQL9 min

Every SQL Join Type in 10 Minutes

OpenRouter (one API for many AI models)9 min

Why OpenRouter Free Models Hit Their Limit So Fast

Gemini API & Google AI Studio9 min

Why Your Gemini API Free Tier Runs Out So Fast

OpenRouter (one API for many AI models)10 min

OpenRouter Will Finally Make Sense After This

Caching & Redis10 min

How Redis Caching Works

Gemini API & Google AI Studio10 min

Gemini API vs Vertex AI: Which One Should You Use?

Gemini API & Google AI Studio8 min

How to Fix a Leaked Gemini API Key

Go (Golang)9 min

Why Golang Uses Goroutines Instead of Threads

Gemini API & Google AI Studio9 min

How to Fix Gemini API Error 429: Resource Exhausted

Claude & the Claude Developer Platform10 min

Claude Token Pricing Will Finally Make Sense After This

Python11 min

Why Python Web Scraping Returns Nothing (and the Fix)

Python10 min

Python uv vs pip: Which One Should You Use?

Python22 min

Python Automation: Full Tutorial for Beginners

Auth (OAuth, JWT)9 min

How OAuth Login Works

Gemini API & Google AI Studio10 min

Google AI Studio Will Finally Make Sense After This

Docker10 min

What Happens When You Run a Docker Container

Claude & the Claude Developer Platform8 min

How to Fix Claude Code Billing Your API Key Instead of Your Plan

Auth (OAuth, JWT)9 min

Why Passkeys Can't Be Phished Like Passwords

PowerShell10 min

PowerShell vs Bash: Which One Should You Learn?

Linux10 min

The Linux Roadmap for Beginners

Django (Python web framework)9 min

Django vs FastAPI: Which One Should You Use?

Databases & SQL10 min

Why SQLite Is the Most Used Database in the World

Databases & SQL11 min

How a NoSQL Database Like MongoDB Works

Python11 min

How to Fix Python pip error: externally-managed-environment

Databases & SQL9 min

How to Fix MySQL Too Many Connections Database Errors

Go (Golang)9 min

Golang Concurrency Will Finally Make Sense After This

AWS10 min

How Amazon S3 Works

Kubernetes10 min

How Kubernetes Works

Git10 min

How Git Works

Docker10 min

How to Fix Docker Port Already Allocated Errors

PostgreSQL10 min

How PostgreSQL Works

Git8 min

How to Fix Git Merge Conflicts

Linux9 min

How to Fix No Space Left on Device in Linux

Networking10 min

How the Internet Works

Databases & SQL9 min

SQL vs NoSQL: When Each One Wins

Auth (OAuth, JWT)8 min

How to Fix JWT Token Expired Errors (401 Unauthorized)

Claude & the Claude Developer Platform9 min

Claude API vs Claude Pro: Why Your Subscription Doesn't Include It

AI agent skills9 min

Why AI Agent Skills Beat Giant Prompts

Linux10 min

Linux Cron Jobs Will Finally Make Sense After This

Cybersecurity10 min

Security Logs Will Finally Make Sense After This

Cybersecurity8 min

How to Fix a Security Leak: An API Key Pushed to GitHub

DNS9 min

DNS Will Finally Make Sense After This

Cybersecurity9 min

Never Ignore a Security Update

Auth (OAuth, JWT)9 min

Two-Factor Authentication Will Finally Make Sense

Networking8 min

Never Expose a Database to the Internet

Cybersecurity10 min

SSH Keys vs Passwords: Which Is Safer for Security?

Linux10 min

The 5 Levels of Linux Boot: From Power On to Login

Networking12 min

The 5 Levels of Network Firewalls

Cybersecurity10 min

Password Security: Why Hackers Crack Weak Passwords

Linux9 min

Why Your Linux Server Runs Out of Memory

Networking10 min

HTTP vs HTTPS: What Actually Changes on Your Network

Linux12 min

Every Linux File Permission You Need to Know

Linux10 min

Linux Processes vs Threads: When Each One Wins

Networking11 min

The OSI Model Will Finally Make Sense After This

Git11 min

The 7 Levels of Git

Networking10 min

Every Network Troubleshooting Command You Need

Cybersecurity10 min

Hashing vs Encryption in Cybersecurity: When Each One Wins

Networking11 min

Why the Internet Ran Out of IP Addresses

Linux11 min

Linux Package Managers: apt vs Snap vs Flatpak

Python9 min

Why Python Is Slow (and When It Doesn't Matter)

Networking11 min

TCP vs UDP: When Each One Wins

Linux8 min

Stop Running Linux as Root (Do This Instead)

Linux11 min

Linux Users and Groups Will Finally Make Sense

Cybersecurity9 min

Why Phishing Beats Good Security (and How to Spot It)

Docker12 min

The 7 Levels of Docker

AI agents & MCP12 min

AI Agents Will Finally Make Sense After This

Git8 min

Stop Using git push --force (Use This Instead)

AI agent skills10 min

Agent Skills vs MCP: When Each One Wins

Networking12 min

Networking Will Finally Make Sense After This

Linux12 min

Every Linux Command You Actually Need

Cybersecurity12 min

The 7 Levels of Cybersecurity

System design12 min

Every System Design Concept You Need, in One Diagram

PostgreSQL10 min

Why PostgreSQL Ignores Your Index