0

I am trying to run my build inside a docker; but I don't want the docker to run on the jenkins master but on another server that has docker running.

What does work:

  • inside jenkins configure a docker Cloud to connect to docker server (using tcp://my-server:4243)
  • configure a docker agent template for certain docker images and assign labels to those docker containers (these need to be containers with sshd running; java installed etc such that they can be connected as jenkins slaves)
  • in my build I specify that I want the build to run on that label

What does not work:

pipeline {
        agent any
        stages {
                stage('test') {
                        steps { script {
                                withDockerServer([uri: 'tcp://my-server:4243']) {
                                        withDockerContainer([image: 'alpine']) {
                                                sh "whoami; pwd; ls /usr/local/bin"
                                        }
                                }
                        } }
                }
        }
}

in this case I get errors:

Caused: java.io.IOException: Cannot run program "docker": error=2, No such file or directory

since docker is not installed on my jenkins master; this means he is trying to execute the docker image on my jenkins master and not on my-server... any tips?

I am using:

  • jenkins 2.150.3
  • docker plugin 1.1.6
  • docker pipeline 1.17

EDIT even with scripted pipeline this does not work:

node('master') {
        withDockerServer([uri: 'tcp://my-server:4243']) {
                withDockerContainer([image: 'alpine']) {
                        sh "whoami; pwd; ls /usr/local/bin"
                }
        }       
}

he is still ignoring withDockerServer (it is shown in the pipeline.log, but the docker command is still run on jenkins master)

0

apparently docker needs to be installed on jenkins master in order for jenkins to be able to launch the docker on the server.

After installation of docker (even without the docker daemon running on jenkins master); jenkins was able to launch the docker on my-server.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.