title: Jenkins Pipeline does not run with docker-compose because it cant connect to docker daemon
body: <p>I am trying to build an docker image and start the container with docker-compose inside a Jenkins pipeline. </p>
  
  <p>I have a custom docker image for my Jenkins where I use the Jenkins out of the box image and install Docker CE and docker compose.</p>
  
  <p>The Dockerfile:</p>
  
  <pre><code>FROM jenkins/jenkins:2.159
  
  USER root
  
  # create dir to save jenkins log files
  RUN mkdir /var/log/jenkins
  RUN chown -R jenkins:jenkins /var/log/jenkins
  
  ########################################################################################################################
  ## install docker based on: https://www.digitalocean.com/community/tutorials/how-to-install-and-use-docker-on-debian-9
  ########################################################################################################################
  RUN apt update
  RUN apt -y install apt-transport-https ca-certificates curl gnupg2 software-properties-common
  RUN curl -fsSL https://download.docker.com/linux/debian/gpg | apt-key add -
  RUN add-apt-repository "deb [arch=amd64] https://download.docker.com/linux/debian $(lsb_release -cs) stable"
  RUN apt update
  # make sure you are about to install from the Docker repo instead of the default Debian repo
  RUN apt-cache policy docker-ce
  RUN apt -y install docker-ce
  #RUN systemctl status docker
  
  # give jenkins docker rights
  RUN apt update
  RUN apt-get install acl
  
  #RUN ls /var/run
  #RUN setfacl -m user:jenkins:rw /var/run/docker.sock
  
  RUN usermod -aG docker jenkins
  RUN gpasswd -a jenkins docker
  
  ################################################################################################################################
  ## install docker-compose based on: https://www.digitalocean.com/community/tutorials/how-to-install-docker-compose-on-debian-9
  ################################################################################################################################
  RUN curl -L https://github.com/docker/compose/releases/download/1.22.0/docker-compose-`uname -s`-`uname -m` -o /usr/local/bin/docker-compose
  RUN chmod +x /usr/local/bin/docker-compose
  RUN docker-compose --version
  
  USER jenkins
  
  RUN id -nG
  
  #tell jenkins to use the created folder to store logs
  </code></pre>
  
  <p>I build this image with <code>docker-compose build</code> with this docker-compose file: </p>
  
  <pre><code>version: '3'
  
  volumes:
    jenkins-log:
    jenkins-data:
  
  networks:
    jenkins-net:
  
  services:
    master:
      build: ./jenkins-master
      ports:
        - "50000:50000"
      volumes:
        - jenkins-log:/var/log/jenkins
        - jenkins-data:/var/jenkins_home
        - /var/run/docker.sock:/var/run/docker.sock
      networks:
        - jenkins-net
  
    nginx:
     build: ./jenkins-nginx
     ports:
        - "80:80"
     networks:
        - jenkins-net
  </code></pre>
  
  <p>And start it with <code>docker-compose -p jenkins up -d</code></p>
  
  <p>This starts Jenkins and works fine for now. </p>
  
  <p>Then I create a Pipeline Job which uses the following Jenkinsfile:</p>
  
  <pre><code>node {
      stage('Build Docker Image') {
          sh '''
              cd env-ci/
              docker-compose --version
              docker --version
              docker-compose build
          '''
      }
  }
  </code></pre>
  
  <p>When I run this pipeline I get the following error: </p>
  
  <pre><code>+ cd env-ci/
  + docker-compose --version
  docker-compose version 1.22.0, build f46880fe
  + docker --version
  Docker version 18.09.1, build 4c52b90
  + docker-compose build
  Couldn't connect to Docker daemon at http+docker://localhost - is it running?
  
  If it's at a non-standard location, specify the URL with the DOCKER_HOST environment variable.
  </code></pre>
  
  <p>When I try to run <code>docker info</code> within the pipeline: </p>
  
  <pre><code>node {
      stage('Build Docker Image') {
          sh '''
              cd env-ci/
              docker-compose --version
              docker --version
              docker info
          '''
      }
  }
  </code></pre>
  
  <p>I get the following error: </p>
  
  <pre><code>+ cd env-ci/
  + docker-compose --version
  docker-compose version 1.22.0, build f46880fe
  + docker --version
  Docker version 18.09.1, build 4c52b90
  + docker info
  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.39/info: dial unix /var/run/docker.sock: connect: permission denied
  </code></pre>
  
  <p>I am currently out of ideas what the issue might be or how I can resolve it. 
  The Jenkins pipeline is run as user <code>jenkins</code> and this user is added to the docker group. So the permission <em>should</em> be fine?!</p>
  
  <p>Does anyone have an idea what might be wrong? 
  Thank you!</p>