Pipeline with multiple docker images loses the ability to docker

6 views
Skip to first unread message

Marc Runkel

unread,
Feb 7, 2020, 10:03:13 AM2/7/20
to Jenkins Users
I am having a problem where after using a custom image on some stages, the following stages suddenly can't access the docker daemon.

Here is the current Jenkinsfile:

pipeline {
  agent any
  options {
    timeout(time: 10, unit: 'MINUTES')
    buildDiscarder(logRotator(numToKeepStr:'4'))
  }
  environment {
    def DOCKER_DRIVER = "overlay2"
    def DOCKER_BUILDKIT=1
    def DOCKER_REG = credentials('cec23a25-eb2e-4331-bb78-940508d74d39')
  }
  stages {
    stage ('Build CSS & JS') {
      agent {
        docker {
          reuseNode true
        }
      }
      steps {
        sh "./build.sh css"
      }
    }
    stage ('Download Database') {
      agent {
        docker {
          reuseNode true
        }
      }
      when {
        not {
          branch 'staging'
        }
      }
      steps {
        withCredentials([
          file(credentialsId: 'aak.env.dev', variable: 'CRAFT_ENV_DEV'),
          file(credentialsId: 'aak.env.stage', variable: 'CRAFT_ENV_STAGE'),
          file(credentialsId: 'aak.env.prod', variable: 'CRAFT_ENV_PROD')
          ]) {
          sh "./build.sh dumpdb"
        }
      }
    }
    stage ('Prep image') {
      agent {
        docker {
          image 'dock.pfdev.de/public/docker-plus'
          reuseNode true
        }
      }
      steps {
        withCredentials([
          sshUserPrivateKey(credentialsId: 'b59c3587-239d-4ed7-9252-a8f6a4eadfb7',
          keyFileVariable: 'SSH_KEY', passphraseVariable: 'SSH_PASS', usernameVariable: 'SSH_USER'),
          file(credentialsId: 'aak.env.dev', variable: 'CRAFT_ENV_DEV'),
          file(credentialsId: 'aak.env.stage', variable: 'CRAFT_ENV_STAGE'),
          file(credentialsId: 'aak.env.prod', variable: 'CRAFT_ENV_PROD')
          ]) {
            sh "./build.sh image"
        }
      }
    }
    stage ('Launch image') {
      agent {
        docker {
          image 'dock.pfdev.de/public/docker-plus'
          reuseNode true
        }
      }
      steps {
        sshagent(['b59c3587-239d-4ed7-9252-a8f6a4eadfb7']) {
          script {
            withCredentials([
              file(credentialsId: 'aak.env.dev', variable: 'CRAFT_ENV_DEV'),
              file(credentialsId: 'aak.env.stage', variable: 'CRAFT_ENV_STAGE'),
              file(credentialsId: 'aak.env.prod', variable: 'CRAFT_ENV_PROD')
            ]) {
            sh "./build.sh launch"
            }
          }
        }
      }
    }
  }
}

If I remove the custom agent from the dump database stage and define the image at the top-level as docker-plus, it works.  Now that I've added the custom agent at that stage (the one for  Build CSS works fine) it doesn't work, both with agent any at the toplevel nor with the image docker-plus at the top level.

The exact error message is:  

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.

 Any and all help would be appreciated!

Thank you,

Marc Runkel
Reply all
Reply to author
Forward
0 new messages