What the message looks like
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 deniedCommon causes
- Your user is not in the
dockergroup. - You were added to the group, but your current session still has the old group list.
- The permissions of
/var/run/docker.sockwere changed. - A script or CI job runs as a different user than you tested with.
- With rootless Docker, the client points to the wrong socket.
Check
- Which groups does your session have?
id - Who owns the socket?
ls -l /var/run/docker.sock - Is the daemon running at all?
systemctl status docker
Fix
- Add your user to the group:
sudo usermod -aG docker $USER. - Log out and in again, or start a shell with the new group:
newgrp docker. - For a quick one-off, run the command with
sudo. - For CI or services, add the service user to the group and restart the service.
- Prefer rootless Docker or Podman if you do not want to hand out root-equivalent rights.
Typical scenario
On a fresh Ubuntu VPS you installed Docker with the convenience script and work as user deploy. docker ps ends with "permission denied … docker.sock", while sudo works. That is by design: the installation only gives root and the docker group access to the socket. Check with id and ls -l /var/run/docker.sock whether your user is in the group and whether the socket belongs to group docker.
FAQ
Is adding a user to the docker group safe?
It is equivalent to giving that user root rights on the host, because a container can mount any directory. Do it only for people you trust as admins.
What if the message says it cannot connect to the daemon at all?
That is a different error: the Docker service is not running. Start it with systemctl start docker and read the journal if it fails.
Why does docker work with sudo, but the runner in my CI does not?
The runner usually runs as its own service user with its own group list. Add exactly that user to the docker group and restart the service, because running processes keep their old groups. Your own login does not matter here.
Should I open the socket with chmod 666?
No. Every local user could then start containers and thereby gain effective root rights. The Docker service also recreates the socket with default permissions on restart, so the change would not even last.
How can I see which groups my current shell really has?
id shows the groups of the running session, id deploy those stored in the system database. If docker is missing only from the first, you have not logged in again since usermod. If it is missing from both, the user was not added.