# Jenkins: Cannot connect to the Docker daemon on Mac

**URL:** <https://community.jenkins.io/t/jenkins-cannot-connect-to-the-docker-daemon-on-mac/9182>\
**Category:** Ask a question\
**Tags:** question, docker, jenkinsfile, pipeline\
**Created:** [August 23, 2023, 4:43pm UTC](https://community.jenkins.io/t/jenkins-cannot-connect-to-the-docker-daemon-on-mac/9182 "2023-08-23T16:43:34Z")\
**Posts on this page:** 3\
**Page:** 1

<div class="post-metadata">

**Author:** ![dev7am](https://avatars.discourse-cdn.com/v4/letter/d/b5e925/32.png) [@dev7am](https://community.jenkins.io/u/dev7am)\
**Post date:** [August 23, 2023, 4:43pm UTC](https://community.jenkins.io/t/jenkins-cannot-connect-to-the-docker-daemon-on-mac/9182/1 "2023-08-23T16:43:34Z")

</div>

I’m running Jenkins for MacOS (using Homebrew) and Docker Desktop on Mac.  
When I try to build docker image for Python app from Jenkins pipeline, the following error is reported:

```auto
+ docker build -t <docker image name>:41 .
ERROR: Cannot connect to the Docker daemon at unix:///var/run/docker.sock. Is the docker daemon running?

```

Jenkinsfile snippet:

```auto
pipeline {
    agent none
    stages {
        ...
            stage("Build Docker Image") {
            agent {
                docker { image 'docker:24.0.5' }
            }
            environment {
        HOME = "${env.WORKSPACE}"
        }
            steps {
               script {
                dockerImage = docker.build("<docker image name>:${env.BUILD_ID}")
               }
            }
        }
        ...
    }
}

```

In previous stages, docker containers are successfully used.  
I found similar case here [Jenkins: Can't connect to Docker daemon - Stack Overflow](https://stackoverflow.com/questions/38105308/jenkins-cant-connect-to-docker-daemon) for CentOS. I assume that I need to add my user to _docker_ group (even if I can already run `docker` commands without `sudo`) but when I run `dscl . list /groups` command (the command which outputs all groups on Mac) I cannot find group named _docker_. I have also tried to run the following in Jenkins pipeline:

```auto
+ whoami
whoami: unknown uid 501

```

Then I ran `id` command from my terminal to compare the _uid_ and this is the _uid_ of my user which I’m currently using and managing Jenkins.  
Thanks in advance for any help.

---

<div class="post-metadata">

**Author:** ![dev7am](https://avatars.discourse-cdn.com/v4/letter/d/b5e925/32.png) [@dev7am](https://community.jenkins.io/u/dev7am)\
**Post date:** [August 25, 2023, 6:18pm UTC](https://community.jenkins.io/t/jenkins-cannot-connect-to-the-docker-daemon-on-mac/9182/2 "2023-08-25T18:18:13Z")

</div>

Last, I created group _docker_:

```auto
sudo dseditgroup -o create docker

```

and added mentioned user to _docker_ group:

```auto
sudo dseditgroup -o edit -a <user> -t user docker

```

and restared Docker Desktop and Jenkins. The issue persists.

---

<div class="post-metadata">

**Author:** ![dev7am](https://avatars.discourse-cdn.com/v4/letter/d/b5e925/32.png) [@dev7am](https://community.jenkins.io/u/dev7am)\
**Post date:** [August 27, 2023, 4:46pm UTC](https://community.jenkins.io/t/jenkins-cannot-connect-to-the-docker-daemon-on-mac/9182/3 "2023-08-27T16:46:54Z")

</div>

I fixed this issue by changing “agent” to “any” in the Jenkins pipeline stage:

```auto
pipeline {
    agent none
    stages {
        ...
            stage("Build Docker Image") {
            agent any
            environment {
        HOME = "${env.WORKSPACE}"
        }
            steps {
               script {
                dockerImage = docker.build("<docker image name>:${env.BUILD_ID}")
               }
            }
        }
        ...
    }
}

```

`docker:24.0.5` docker image was not working due to docker-in-docker scenario. Now, the docker image is successfully built on my local docker engine.
