Uploaded image for project: 'Jenkins'
  1. Jenkins
  2. JENKINS-34194

docker volume mounts not working as expected when run from within swarm container

XMLWordPrintable

    • Icon: Bug Bug
    • Resolution: Not A Defect
    • Icon: Trivial Trivial
    • Ubuntu 14.04.4, Jenkins 1.642.2 (workflow/pipeline 1.15, docker-workflow 1.2), Jenkins 1.642.4 (workflow/pipeline 2.x, docker-workflow 1.4), swarm 2.0

      It appears that Jenkins is running within a jail under swarm and/or workflow (running in a docker container with /var/lib/jenkins and /var/run/docker.sock bind-mounted from host) which is preventing bind mounts from working as expected from both docker.image().inside and sh workflow steps.

      PLEASE NOTE: this is also happening when simply running docker from `sh` (see script/results below)

      Script, results, and plugins below:

      workflow/pipeline script
      node ('build && docker') {
          wrap([$class: 'TimestamperBuildWrapper']) {
              sh 'hostname'
          
              sh 'docker version'
          
              echo 'DOCKER (as jenkins)'
              sh 'docker run -t -u 1000:1000 -v $(pwd):$(pwd):rw -w $(pwd) buildpack-deps:jessie-scm bash -c \'pwd; touch herp; ls -alF\''
          
              echo 'DOCKER (as root)'
              sh 'docker run -t -u 0:0 -v $(pwd):$(pwd):rw -w $(pwd) buildpack-deps:jessie-scm bash -c \'pwd; touch herp; ls -alF\''
          
              echo 'BASH'
              sh 'pwd; touch derp; ls -alF'
              
              docker.image('buildpack-deps:jessie-scm').inside {
                  sh 'bash -c \'pwd; touch inside; ls -alF\''
              }
          }
      }
      
      workflow/pipeline results
      Started by user Jacob Blain Christen
      [Pipeline] Allocate node : Start
      Running on build-c8c3e683 in /var/lib/jenkins/workspace/USERS/JCHRISTEN/jenkins-docker-workflow-bug
      [Pipeline] node {
      [Pipeline] General Build Wrapper : Start
      [Pipeline] wrap {
      [Pipeline] sh
      23:44:47 [jenkins-docker-workflow-bug] Running shell script
      23:44:47 + hostname
      23:44:47 8dcf8118ebe6
      [Pipeline] sh
      23:44:47 [jenkins-docker-workflow-bug] Running shell script
      23:44:47 + docker version
      23:44:48 Client:
      23:44:48  Version:      1.10.3
      23:44:48  API version:  1.22
      23:44:48  Go version:   go1.5.3
      23:44:48  Git commit:   20f81dd
      23:44:48  Built:        Thu Mar 10 21:49:11 2016
      23:44:48  OS/Arch:      linux/amd64
      23:44:48 
      23:44:48 Server:
      23:44:48  Version:      1.10.2
      23:44:48  API version:  1.22
      23:44:48  Go version:   go1.5.3
      23:44:48  Git commit:   c3959b1
      23:44:48  Built:        Mon Feb 22 21:37:01 2016
      23:44:48  OS/Arch:      linux/amd64
      [Pipeline] echo
      23:44:48 DOCKER (as jenkins)
      [Pipeline] sh
      23:44:48 [jenkins-docker-workflow-bug] Running shell script
      23:44:49 + pwd
      23:44:49 + pwd
      23:44:49 + pwd
      23:44:49 + docker run -t -u 1000:1000 -v /var/lib/jenkins/workspace/USERS/JCHRISTEN/jenkins-docker-workflow-bug:/var/lib/jenkins/workspace/USERS/JCHRISTEN/jenkins-docker-workflow-bug:rw -w /var/lib/jenkins/workspace/USERS/JCHRISTEN/jenkins-docker-workflow-bug buildpack-deps:jessie-scm bash -c pwd; touch herp; ls -alF
      23:44:49 /var/lib/jenkins/workspace/USERS/JCHRISTEN/jenkins-docker-workflow-bug
      23:44:49 touch: cannot touch 'herp': Permission denied
      23:44:49 total 8
      23:44:49 drwxr-xr-x 2 root root 4096 Apr 13 06:39 ./
      23:44:49 drwxr-xr-x 3 root root 4096 Apr 13 06:45 ../
      [Pipeline] echo
      23:44:49 DOCKER (as root)
      [Pipeline] sh
      23:44:49 [jenkins-docker-workflow-bug] Running shell script
      23:44:50 + pwd
      23:44:50 + pwd
      23:44:50 + pwd
      23:44:50 + docker run -t -u 0:0 -v /var/lib/jenkins/workspace/USERS/JCHRISTEN/jenkins-docker-workflow-bug:/var/lib/jenkins/workspace/USERS/JCHRISTEN/jenkins-docker-workflow-bug:rw -w /var/lib/jenkins/workspace/USERS/JCHRISTEN/jenkins-docker-workflow-bug buildpack-deps:jessie-scm bash -c pwd; touch herp; ls -alF
      23:44:50 /var/lib/jenkins/workspace/USERS/JCHRISTEN/jenkins-docker-workflow-bug
      23:44:50 total 8
      23:44:50 drwxr-xr-x 2 root root 4096 Apr 13 06:45 ./
      23:44:50 drwxr-xr-x 3 root root 4096 Apr 13 06:45 ../
      23:44:50 -rw-r--r-- 1 root root    0 Apr 13 06:45 herp
      [Pipeline] echo
      23:44:51 BASH
      [Pipeline] sh
      23:44:51 [jenkins-docker-workflow-bug] Running shell script
      23:44:51 + pwd
      23:44:51 /var/lib/jenkins/workspace/USERS/JCHRISTEN/jenkins-docker-workflow-bug
      23:44:51 + touch derp
      23:44:51 + ls -alF
      23:44:51 total 8
      23:44:51 drwxr-xr-x  2 jenkins jenkins 4096 Apr 13 06:39 ./
      23:44:51 drwxr-xr-x 13 jenkins jenkins 4096 Apr 13 06:39 ../
      23:44:51 -rw-r--r--  1 jenkins jenkins    0 Apr 13 06:45 derp
      [Pipeline] sh
      23:44:52 [jenkins-docker-workflow-bug] Running shell script
      23:44:52 + docker inspect -f . buildpack-deps:jessie-scm
      23:44:52 .
      [Pipeline] Run build steps inside a Docker container : Start
      23:44:52 $ docker run -t -d -u 1000:1000 -w /var/lib/jenkins/workspace/USERS/JCHRISTEN/jenkins-docker-workflow-bug -v /var/lib/jenkins/workspace/USERS/JCHRISTEN/jenkins-docker-workflow-bug:/var/lib/jenkins/workspace/USERS/JCHRISTEN/jenkins-docker-workflow-bug:rw -v /var/lib/jenkins/workspace/USERS/JCHRISTEN/jenkins-docker-workflow-bug@tmp:/var/lib/jenkins/workspace/USERS/JCHRISTEN/jenkins-docker-workflow-bug@tmp:rw -e ******** -e ******** -e ******** -e ******** -e ******** -e ******** -e ******** -e ******** -e ******** -e ******** -e ******** -e ******** -e ******** -e ******** -e ******** -e ******** buildpack-deps:jessie-scm cat
      [Pipeline] withDockerContainer {
      [Pipeline] sh
      23:44:53 [jenkins-docker-workflow-bug] Running shell script
      23:44:53 sh: 1: cannot create /var/lib/jenkins/workspace/USERS/JCHRISTEN/jenkins-docker-workflow-bug@tmp/durable-aff93f64/pid: Directory nonexistent
      23:44:53 sh: 1: cannot create /var/lib/jenkins/workspace/USERS/JCHRISTEN/jenkins-docker-workflow-bug@tmp/durable-aff93f64/jenkins-log.txt: Directory nonexistent
      23:44:53 sh: 1: cannot create /var/lib/jenkins/workspace/USERS/JCHRISTEN/jenkins-docker-workflow-bug@tmp/durable-aff93f64/jenkins-result.txt: Directory nonexistent
      [Pipeline] } //withDockerContainer
      23:45:11 $ docker stop e2b796e31144c833523fef97cff5a21352d05abb2c13453b494dd60dfcd5e95c
      23:45:21 $ docker rm -f e2b796e31144c833523fef97cff5a21352d05abb2c13453b494dd60dfcd5e95c
      [Pipeline] Run build steps inside a Docker container : End
      [Pipeline] } //wrap
      [Pipeline] General Build Wrapper : End
      [Pipeline] } //node
      [Pipeline] Allocate node : End
      [Pipeline] End of Pipeline
      ERROR: script returned exit code -2
      Finished: FAILURE
      
      plugins
      ace-editor	1.1	true	false
      ant	1.2	true	false
      antisamy-markup-formatter	1.1	true	false
      authentication-tokens	1.2	true	true
      branch-api	1.6	true	false
      build-monitor-plugin	1.8+build.201601112328	true	false
      build-name-setter	1.5.1	true	true
      build-with-parameters	1.3	true	false
      cloudbees-bitbucket-branch-source	1.4	true	false
      cloudbees-folder	5.8	true	true
      credentials	1.27	true	true
      credentials-binding	1.7	true	false
      cvs	2.11	true	false
      docker-commons	1.3.1	true	false
      docker-workflow	1.4	true	false
      durable-task	1.9	true	false
      embeddable-build-status	1.9	true	false
      external-monitor-job	1.4	true	false
      git	2.4.4	true	false
      git-client	1.19.6	true	false
      git-server	1.6	true	false
      github	1.18.2	true	false
      github-api	1.72.1	true	false
      github-branch-source	1.5	true	false
      gravatar	2.1	true	false
      greenballs	1.15	true	false
      groovy	1.29	true	false
      groovy-postbuild	2.3.1	true	false
      handlebars	1.1.1	true	false
      hipchat	1.0.0	true	false
      icon-shim	2.0.3	true	true
      javadoc	1.1	true	false
      job-dsl	1.45	true	false
      jquery-detached	1.2.1	true	false
      junit	1.11	true	true
      ldap	1.11	true	true
      mailer	1.16	true	true
      mapdb-api	1.0.6.0	true	false
      matrix-auth	1.3.2	true	true
      matrix-project	1.6	true	true
      maven-plugin	2.12.1	true	true
      mercurial	1.54	true	false
      momentjs	1.1.1	true	false
      pam-auth	1.1	true	false
      parameterized-trigger	2.30	true	false
      pegdown-formatter	1.3	true	true
      pipeline-build-step	2.0	true	false
      pipeline-input-step	2.0	true	false
      pipeline-rest-api	1.3	true	false
      pipeline-stage-step	2.0	true	false
      pipeline-stage-view	1.3	true	false
      pipeline-utility-steps	1.1.4	true	false
      plain-credentials	1.1	true	false
      project-description-setter	1.1	true	false
      rebuild	1.25	true	false
      scm-api	1.2	true	false
      script-security	1.18.1	true	true
      ssh-agent	1.10	true	false
      ssh-credentials	1.11	true	true
      ssh-slaves	1.10	true	true
      structs	1.1	true	false
      subversion	2.5.7	true	true
      swarm	2.0	true	true
      systemloadaverage-monitor	1.2	true	false
      throttle-concurrents	1.9.0	true	false
      timestamper	1.7.4	true	true
      token-macro	1.12.1	true	true
      translation	1.10	true	false
      violations	0.7.11	true	false
      windows-slaves	1.1	true	true
      workflow-aggregator	2.0	true	false
      workflow-api	2.0	true	false
      workflow-basic-steps	2.0	true	false
      workflow-cps	2.1	true	false
      workflow-cps-global-lib	2.0	true	false
      workflow-durable-task-step	2.0	true	false
      workflow-job	2.0	true	false
      workflow-multibranch	2.1	true	false
      workflow-scm-step	2.0	true	false
      workflow-step-api	2.0	true	false
      workflow-support	2.0	true	false
      

            jglick Jesse Glick
            dweomer Jacob Blain Christen
            Votes:
            0 Vote for this issue
            Watchers:
            3 Start watching this issue

              Created:
              Updated:
              Resolved: