# Jenkins: Got permission denied while trying to connect to the Docker daemon socket at unix:///var/run/docker.sock

**Code:** `permission denied /var/run/docker.sock` · **Category:** CI/CD · **Seen on:** Jenkins, Docker, Linux

The Jenkins user is not allowed to talk to Docker — it is not in the `docker` group or the socket is not mounted in the container.

## Meaning

Docker's socket is root-owned with group `docker`. Add the `jenkins` user to that group and restart Jenkins, or when Jenkins runs in a container, mount the socket and match the host's docker GID. Understand that this gives the build root-equivalent power on the host.

## Common causes

- `jenkins` user not in the `docker` group
- Jenkins not restarted after group change
- Container without `/var/run/docker.sock` mounted
- Docker GID differs between host and container
- Rootless Docker using a different socket path

## Quick fix

1. `sudo usermod -aG docker jenkins` and restart Jenkins
2. Mount `-v /var/run/docker.sock:/var/run/docker.sock` and add the matching `--group-add`
3. Consider rootless builds (Kaniko, Buildah) for untrusted code

## Detailed fix by platform

### Linux

1. `id jenkins` then `sudo systemctl restart jenkins`
2. Check GID: `stat -c '%g' /var/run/docker.sock`

## How to diagnose

1. **User** — jenkins in docker group?
2. **Restart** — Service restarted?
3. **Socket** — Mounted into the container?

---
Source: [WhatIsMyError](https://whatismyerror.com/errors/cicd/jenkins-docker-sock-permission-denied)
