Answers: <p>apparently <code>docker</code> needs to be installed on jenkins master in order for jenkins to be able to launch the docker on the server.</p>
  
  <p>After installation of <code>docker</code> (even without the <code>docker</code> daemon running on jenkins master); jenkins was able to launch the docker on <strong>my-server</strong>.</p>
  
Answers: CC BY-SA 4.0
Answers: 2019-05-10T09:10:51.087Z
Answers: 2019-05-10T09:10:51.087Z
Answers: Chris Maes
Body: <p>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.</p>
  
  <p>What does work:</p>
  
  <ul>
  <li>inside jenkins configure a docker Cloud to connect to docker server (using tcp://my-server:4243)</li>
  <li>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)</li>
  <li>in my build I specify that I want the build to run on that label</li>
  </ul>
  
  <p>What does not work:</p>
  
  <pre><code>pipeline {
          agent any
          stages {
                  stage('test') {
                          steps { script {
                                  withDockerServer([uri: 'tcp://my-server:4243']) {
                                          withDockerContainer([image: 'alpine']) {
                                                  sh "whoami; pwd; ls /usr/local/bin"
                                          }
                                  }
                          } }
                  }
          }
  }
  </code></pre>
  
  <p>in this case I get errors:</p>
  
  <pre><code>Caused: java.io.IOException: Cannot run program "docker": error=2, No such file or directory
  </code></pre>
  
  <p>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?</p>
  
  <p>I am using:</p>
  
  <ul>
  <li>jenkins 2.150.3</li>
  <li>docker plugin 1.1.6</li>
  <li>docker pipeline 1.17</li>
  </ul>
  
  <p><strong>EDIT</strong>
  even with scripted pipeline this does not work:</p>
  
  <pre><code>node('master') {
          withDockerServer([uri: 'tcp://my-server:4243']) {
                  withDockerContainer([image: 'alpine']) {
                          sh "whoami; pwd; ls /usr/local/bin"
                  }
          }       
  }
  </code></pre>
  
  <p>he is still ignoring <code>withDockerServer</code> (it is shown in the pipeline.log, but the docker command is still run on jenkins master)</p>
  
Tags: <docker><jenkins><jenkins-pipeline>
Title: Jenkins run build in docker on server (withDockerServer not working)
UserDisplayName: Chris Maes
ThreadText: # Jenkins run build in docker on server (withDockerServer not working)
  
  (Asked by: username_0 on 2019-05-10)
  
  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)
  
  **Tags:** docker, jenkins, jenkins-pipeline
  
  
  ---
  
  ## 1 answers
  
  ### Answer by username_0 on 2019-05-10. Score: 1
  
  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**.
  
  
  ---
  
  