Getting “Permission Denied” error when trying to build a docker image in Jenkins on Mac

I am using Jenkins version 2.121.1 with Pipeline On MacOS-HighSierra.

I’ve a shell script called build_docker_image.sh that builds a docker image using the following command:

docker build -t test_api:1 -f test-dockerfile
test-dockerfile is a Dockerfile and has instructions to build an image.

From CLI the whole set up works! However, when I run it from Jenkins server Pipeline context, it is failing at the above line with an error:

Got permission denied while trying to connect to the Docker daemon socket at unix:///var/run/docker.sock: Post http://%2Fvar%2Frun%2Fdocker.sock/v1.37/build?buildargs=%7B%7D&cachefrom=%5B%5D&cgroupparent=&cpuperiod=0&cpuquota=0&cpusetcpus=&cpusetmems=&cpushares=0&dockerfile=.dockerfile.14bce80e6f0b4b9d7b36&labels=%7B%7D&memory=0&memswap=0&networkmode=default&rm=1&session=2fab4ca31a7ca7b7eceddf80e02de5a7089dc10f50db250d2249e059d7ecfb61&shmsize=0&t=login_api%3A100_i&target=&ulimits=null: dial unix /var/run/docker.sock: connect: permission denied

The step that triggers from Jenkins server is simple. Just call the script:

stage (‘Build-Docker-Image’) {
steps {
sh ‘/path/to/build-docker_image.sh’
}
}
I made sure Jenkins user has “admin” permission and member of “staff” group. I printed out them in the shell script too as below:

WHOAMI
jenkins ID = uid=267(jenkins) gid=20(staff) egid=1(daemon) groups=267(jenkins),12(everyone),20(staff),61(localaccounts),80(admin),701(com.apple.sharepoint.group.1),33(_appstore),98(_lpadmin),100(_lpoperator),204(_developer),250(_analyticsusers),395(com.apple.access_ftp),398(com.apple.access_screensharing),399(com.apple.access_ssh)

I followed the workaround steps mentioned here: Using Docker for Mac with multiple users · Issue #799 · docker/for-mac · GitHub. I’ve rebooted Docker on my Mac several times too. It did not help.

2 Likes

Any suggestions on this?

Did you find any solution this issue, I am also facing same issue.
I have Jenkins & dockers installed on my mac.
When I login as Jenkins user I am getting permission denied error.
I tried all work arounds found by googling but none helped. I have created docker group, added jenkins user to this group. I even added jenkins to staff, admin groups but still same error.

Anyone any leads on this issue would greatly appreciate.

When you see this “permission denied while trying to connect to the Docker daemon socket at unix:///var/run/docker.sock” it means the user trying to run docker, “jenkins” in that case, is not authorized to access the docker socket. To remediate you need to add jenkins to the group docker.

usermod -a -G docker jenkins

Has anyone found a solution to this issue? Two days now! The pain is unbearable :grinning:

I tried sudo to run and it works.