Short answer
Your user may not open Docker’s socket, which belongs to root and the docker group. Run sudo usermod -aG docker $USER, then log out and log in again: the group counts only from a new login. Docker 29 words the error “…connect to the docker API at unix:///var/run/docker.sock”; older releases said “…the Docker daemon socket”. Do not chmod 666 the socket.
Tested on Ubuntu 26.04 and 24.04, two separate runs. On 24.04, every step is the same. Everything that differed
The error
Right after installing Docker (install Docker on Ubuntu), any docker command without sudo, as a normal sudo user, gives:
$ docker pspermission denied while trying to connect to the docker API at unix:///var/run/docker.sockThe docker command does not run containers itself. It sends requests to the Docker engine over a socket file, /var/run/docker.sock. “Permission denied” means the file system refused to let your user open that file. It is not about the engine, your image or your files.
Why it happens
$ ls -l /var/run/docker.socksrw-rw---- 1 root docker 0 Nov 18 23:04 /var/run/docker.socks is a socket, rw-rw---- lets the owner (root) and the group (docker) in, and nobody else. Your user is in sudo, not in docker:
$ iduid=1000(deploy) gid=1000(deploy) groups=1000(deploy),27(sudo),100(users)With sudo the command runs as root, so it gets in. That also proves the engine is fine and only access is missing:
$ sudo docker psCONTAINER ID IMAGE COMMAND CREATED STATUS PORTS NAMESThe fix: join the docker group, then log in again
Add your user to the group. -a adds it to the groups you have; without it, -G would replace them. In the test, docker ps ran right after it, in the same login:
$ sudo usermod -aG docker $USER$ docker pspermission denied while trying to connect to the docker API at unix:///var/run/docker.sockStill refused, and this is why so many people think the fix failed. Linux gives a process its groups when you log in, so your open session does not have the new group yet. Log out (exit), connect again over SSH, and check:
$ id -nGdeploy sudo users docker$ docker psCONTAINER ID IMAGE COMMAND CREATED STATUS PORTS NAMESdocker is in the list and the command works without sudo. A real container to be sure:
$ docker run --rm hello-world[… 19 lines not shown …]To try something more ambitious, you can run an Ubuntu container with: $ docker run -it ubuntu bash Share images, automate workflows, and more with a free Docker ID: https://hub.docker.com/ For more examples and ideas, visit: https://docs.docker.com/get-started/What the docker group really gives
The engine runs as root and does what a docker-group user asks, including mounting any folder of the server into a container. The test user cannot read root’s home folder:
$ ls -la /rootls: cannot open directory '/root': Permission deniedThrough docker, with no sudo and no password, it can:
$ docker run --rm -v /root:/host-root alpine ls -la /host-root[… 7 lines not shown …]total 24drwx------ 4 root root 4096 Nov 18 23:03 .drwxr-xr-x 1 root root 4096 Nov 18 23:05 ..-rw-r--r-- 1 root root 3106 Apr 20 2026 .bashrcdrwx------ 2 root root 4096 Nov 18 23:03 .cache-rw-r--r-- 1 root root 132 Apr 20 2026 .profiledrwx------ 2 root root 4096 Nov 18 23:03 .sshThe same works for /etc or any other folder, for writing as well as reading. So treat the docker group like the sudo group. On a server shared with people you do not trust that far, look at Docker’s rootless mode instead, where each user runs their own engine without root.
Why not chmod 666 on docker.sock
Many answers online give sudo chmod 666 /var/run/docker.sock. It makes the error go away, for everyone. The test server had a second, ordinary user, intern, in no special group. Before the change:
$ sudo -u intern docker pspermission denied while trying to connect to the docker API at unix:///var/run/docker.sock$ sudo chmod 666 /var/run/docker.sock$ ls -l /var/run/docker.socksrw-rw-rw- 1 root docker 0 Nov 18 23:04 /var/run/docker.sock$ sudo -u intern docker psCONTAINER ID IMAGE COMMAND CREATED STATUS PORTS NAMESintern is now in, with root’s power through Docker, as is any web app or script that is ever broken into. And it does not even last. systemd makes the socket again with 0660 every time Docker starts. After a reboot:
$ ls -l /var/run/docker.socksrw-rw---- 1 root docker 0 Nov 18 23:05 /var/run/docker.sockBack to srw-rw----, and the error is back for anyone outside the group. The group is the fix that is both deliberate and permanent.
“Cannot connect to the Docker daemon. Is the docker daemon running?”
This looks similar but has a different cause: nothing is answering on the socket, because Docker is stopped. In the test Docker was stopped on purpose (sudo systemctl stop docker.socket docker.service):
$ docker psCannot connect to the Docker daemon at unix:///var/run/docker.sock. Is the docker daemon running?Group changes do not help here. Start it, and check systemctl status docker if it will not start:
$ sudo systemctl start docker$ docker psCONTAINER ID IMAGE COMMAND CREATED STATUS PORTS NAMESWhat the fix changed on the server
Both runs recorded the server before the first step and after the last (see the Tested on box below): only the group files changed (/etc/group, /etc/gshadow and their backups), because usermod added you to the docker group. No package, service, open port or other file in /etc changed: the chmod 666 was gone after the reboot.
Ubuntu 26.04 vs 24.04
The same check ran on a fresh 26.04 server and on a fresh 24.04 server, each with its own run log. Every command printed the same on both, error messages included; only download progress and file dates differed. So this page applies to both as written:
| What | Ubuntu 26.04 | Ubuntu 24.04 |
|---|---|---|
| System | Ubuntu 26.04.1 LTS7.0.0-43-generic | Ubuntu 24.04.5 LTS6.8.0-147-generic |
| docker-ce | 5:29.10.0-1~ubuntu.26.04~resolute | 5:29.10.0-1~ubuntu.24.04~noble |
| docker-ce-cli | 5:29.10.0-1~ubuntu.26.04~resolute | 5:29.10.0-1~ubuntu.24.04~noble |
| containerd.io | 2.4.2-4~ubuntu.26.04~resolute | 2.4.2-4~ubuntu.24.04~noble |
| Commands and results | The same on every release: the same commands, the same results. | |
| Proof | Run log, 23 checks passed | Run log, 23 checks passed |
Undo: take a user out of the docker group
$ sudo gpasswd -d $USER dockerRemoving user deploy from group dockerLike adding, it counts from the next login. After logging in again the error is back, and sudo docker still works:
$ docker pspermission denied while trying to connect to the docker API at unix:///var/run/docker.sock