Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Permission Denied while trying to connect to Docker Daemon while running Jenkins pipeline in Macbook

I am trying to run Jenkins pipeline job in my macbook. I also have docker instance running locally. Initially I got the "docker command not found" error while running the Jenkins Job. I fixed the error by adding a symlink "ln -f -s /Applications/Docker.app/Contents/Resources/bin/* /usr/local/bin"

I also applied these two changes so that jenkins user has the access to the docker directory

  1. chmod -R 777 /Users/myUserName/Library/Containers/com.docker.docker/
  2. chmod -R 777 /Users/myUserName/Library/Containers/com.docker.helper/

I am getting below errors:

Got permission denied while trying to connect to the Docker daemon socket at unix:///var/run/docker.sock: Get http://%2Fvar%2Frun%2Fdocker.sock/v1.27/containers/openjdk:8/json: dial unix /var/run/docker.sock: connect: permission denied [Pipeline] sh [test] Running shell script + docker pull openjdk:8 Warning: failed to get default registry endpoint from daemon (Got permission denied while trying to connect to the Docker daemon socket at unix:///var/run/docker.sock: Get http://%2Fvar%2Frun%2Fdocker.sock/v1.27/info: dial unix /var/run/docker.sock: connect: permission denied). Using system default: https://index.docker.io/v1/ 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.27/images/create?fromImage=openjdk&tag=8: dial unix /var/run/docker.sock: connect: permission denied [Pipeline] } [Pipeline] // node [Pipeline] End of Pipeline ERROR: script returned exit code 1 Finished: FAILURE

like image 264
Sameer Malhotra Avatar asked Jul 07 '17 19:07

Sameer Malhotra


People also ask

How do I fix Docker has permission denied while trying to connect?

Fix 1: Run all the docker commands with sudo If you have sudo access on your system, you may run each docker command with sudo and you won't see this 'Got permission denied while trying to connect to the Docker daemon socket' anymore. But running each and every docker command with sudo is super inconvenient.

How do I enable Docker daemon on Mac?

On MacOS go to the whale in the taskbar > Preferences > Daemon > Advanced. You can also start the Docker daemon manually and configure it using flags. This can be useful for troubleshooting problems.

How do I give Jenkins access to Docker?

Compose Configuration (Linux or macOS) Add a group docker if it does not exist, and add jenkins user to the docker group, e.g. groupadd docker && usermode -aG docker 'jenkins' . Adjust permissions on the docker. sock file so that jenkins user can access it, e.g. chmod 777 /var/run/docker. sock .


1 Answers

This is a docker permission issue. Add the jenkins user to docker group as follow:

usermod -aG docker ${USER}

like image 94
Innocent Anigbo Avatar answered Oct 05 '22 23:10

Innocent Anigbo