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

  • deploy containers on swarm cluster using compose file without using docker machine
  • How does Docker share resources
  • Docker on RHEL 6 Cgroup mounting failing
  • unable to access mailpile server inside docker container
  • Docker - Elasticsearch - Failed to establish a new connection: [Errno 111] Connection refused',))
  • Install Docker script error - permission denied
    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

  • Running Ruby Sinatra inside a Docker container not able to connect (via Mac host) or find commands (in different scenario)?
  • Running commands in a Docker file
  • What is the better way to do service discovery on Docker environment?
  • Mounting a directory to docker container
  • Docker CPU percentage
  • Docker Node JS Installation
  • 2 Solutions collect form web for “Permission Denied while trying to connect to Docker Daemon while running Jenkins pipeline in Macbook”

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

    usermod -aG docker ${USER}

    There are any ways to solve this issue, I faced it last week, I solved but with docker-compose this setup is replicable to docker, you can create a shared volume that points from the location of docker.sock in your host /var/run/docker.sock to location of docker.sock in your container /var/run/docker.sock. Something like this:

    version: '2'
    services:
      jenkins:
        build:
          context: ./jenkins
        ports:
          - "8080:8080"
        expose:
          - "8080"
        volumes:
          - /var/run/docker.sock:/var/run/docker.sock
          - /usr/bin/docker:/usr/bin/docker
          - /usr/local/bin/docker-compose:/usr/local/bin/docker-compose
    
      nginx:
        build:
          context: ./nginx
        container_name: "prueba"
        links:
          - jenkins
        ports:
          - "80:80"
        depends_on:
          - jenkins
    

    To works well you have to give permissons of user to the socketsudo chown $USER:$USER /var/run/docker.sock and to the group of docker , as Innocent Anigbo mentioned.

    Docker will be the best open platform for developers and sysadmins to build, ship, and run distributed applications.