The Error
You run docker ps or docker build and get:
permission denied while trying to connect to the Docker daemon socket at
unix:///var/run/docker.sock: Get "http://%2Fvar%2Frun%2Fdocker.sock/v1.47/containers/json":
dial unix /var/run/docker.sock: connect: permission deniedDocker commands talk to the Docker daemon through a Unix socket file, /var/run/docker.sock. This error means your user isn't allowed to open that file. It's almost always a permissions setup issue, not a broken Docker install.
๐ฏ Quick Fix (30 Seconds)
On Linux, add your user to the docker group, then refresh your session:
sudo groupadd docker # may say "already exists", that's fine
sudo usermod -aG docker $USER
newgrp docker # or log out and log back in
docker run hello-world # testIf that doesn't work, go through the checklist below.
Why It Happens
(your user)"] -->|"open /var/run/docker.sock"| SOCK[("docker.sock
owner: root
group: docker
mode: srw-rw----")] SOCK --> D["Docker daemon
(dockerd, runs as root)"] U{"Is your user root
or in group 'docker'?"} -->|No| X["โ permission denied"] U -->|Yes| OK["โ connected"]
The socket is owned by root and the docker group, with read/write for both. Any user in the docker group can use it without sudo.
Fix by Situation
1. Linux: user not in the docker group (most common)
Check:
groups # is 'docker' in the list?
ls -l /var/run/docker.sock # expect: srw-rw---- 1 root docker ...Fix with the commands in the Quick Fix above. Group changes only apply to new login sessions, which is why people add themselves to the group and still see the error. Run newgrp docker, log out and back in, or reboot.
2. The daemon isn't running
If the daemon is stopped, you may see "Cannot connect to the Docker daemon" or a permission error on some setups.
sudo systemctl status docker
sudo systemctl enable --now docker3. Socket has the wrong group
If ls -l /var/run/docker.sock shows root root instead of root docker:
sudo chown root:docker /var/run/docker.sock
sudo systemctl restart docker4. Docker Desktop on Mac or Windows
Docker Desktop manages the socket for you. If you get this error:
- Make sure Docker Desktop is running (whale icon in the menu bar / tray).
- Restart Docker Desktop.
- Check your Docker context:
docker context ls, thendocker context use desktop-linux(Mac) if it points somewhere else.
5. WSL 2 (Windows)
- Using Docker Desktop? Enable Settings โ Resources โ WSL Integration for your distro.
- Running Docker Engine directly inside WSL? Apply the Linux fix (#1) and start the service:
sudo service docker start.
6. CI runners and Jenkins
The CI user (for example jenkins or gitlab-runner) needs the same group membership:
sudo usermod -aG docker jenkins
sudo systemctl restart jenkinsOn GitHub Actions hosted runners, Docker works out of the box. Self-hosted runners need the runner's user added to the docker group and the runner service restarted.
7. Snap-installed Docker (Ubuntu)
Snap packages can behave differently. If the group fix doesn't work, removing the snap and installing Docker Engine from Docker's official apt repository usually resolves it.
What NOT to Do
sudo chmod 666 /var/run/docker.sock or chmod 777. It "works," but lets every user and process on the machine control Docker, and the change is lost on restart anyway. Use the docker group instead.
Also know the trade-off of the proper fix: membership in the docker group is effectively root access, because anyone who can run containers can mount the host filesystem. Only add trusted users. If that's a concern, look at rootless Docker or Podman.
Troubleshooting Checklist
-
groupsshowsdocker - You started a new session after adding yourself
-
systemctl status dockershows active (running) -
/var/run/docker.sockis owned byroot:docker - On Mac/Windows: Docker Desktop is running and the context is correct
-
docker run hello-worldworks withoutsudo
Frequently Asked Questions
Why do I still get permission denied after adding myself to the docker group?
Group membership is read when you log in, so your current terminal session doesn't know about the new group. Run newgrp docker, open a new login session, log out and back in, or reboot. Then check with the groups command.
Is it safe to add my user to the docker group?
It's the standard approach, but the docker group grants root-level privileges on the host, because containers can mount system directories. Add only trusted users. For stronger isolation, use rootless Docker or Podman.
Should I just use sudo for every docker command?
It works, but it's inconvenient and can create files owned by root in your project folders. Adding your user to the docker group, or using rootless mode, is the cleaner long-term setup.
Conclusion
"Permission denied while trying to connect to the Docker daemon socket" means your user can't open /var/run/docker.sock. On Linux, add yourself to the docker group and start a new session. On Mac and Windows, make sure Docker Desktop is running. Avoid chmod 666 on the socket, and remember the docker group is effectively root.
Sources
- Docker docs: Linux post-installation steps
- Docker docs: Rootless mode
- Docker docs: Docker Desktop WSL 2 backend
Last verified: 2 November 2026.
Related reads: Kubernetes Explained ยท CI/CD Explained ยท Fix Python ModuleNotFoundError
I write practical guides for developers. Follow on LinkedIn or X, or invite me to speak.