Pipeline with multiple docker images loses the ability to docker

classic Classic list List threaded Threaded
1 message Options
Reply | Threaded
Open this post in threaded view
|

Pipeline with multiple docker images loses the ability to docker

Marc Runkel
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 {
          image 'dock.pfdev.de/public/craft-build:latest'
          reuseNode true
        }
      }
      steps {
        sh "./build.sh css"
      }
    }
    stage ('Download Database') {
      agent {
        docker {
          image 'dock.pfdev.de/public/php-nginx-base:latest'
          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

--
You received this message because you are subscribed to the Google Groups "Jenkins Users" group.
To unsubscribe from this group and stop receiving emails from it, send an email to [hidden email].
To view this discussion on the web visit https://groups.google.com/d/msgid/jenkinsci-users/0377fc52-998a-4ec4-8ae5-aec408496ed1%40googlegroups.com.