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

docker.inside not mounting additional volumes

XMLWordPrintable

    • Icon: Bug Bug
    • Resolution: Not A Defect
    • Icon: Minor Minor
    • docker-workflow-plugin
    • None
    • BS Centos7, Jenkins 2.97, docker-workflow-plugin 1.14

      When mounting an additional volume using docker.inside(), the volume is not mounted in the container.

      We rely on this feature to avoid repeatedly Maven artifacts downloads, by mounting /var/lib/jenkins/.m2/repository/${EXECUTOR_NUMBER} inside the container.

      PoC: 

      node('docker') {
          deleteDir()
          stage('build') {
              myimage = docker.image('ubuntu')
              myimage.pull()
              sh 'ls -la /tmp'
              myimage.inside("-v /tmp:/mnt)") {
                  sh 'ls -la /mnt'
              }
          }
      }
      

      Console output

      [Pipeline] node
      Running on centos-buildserver-03 in /var/lib/jenkins/workspace/Tests/withMaven_tests/withMaven-test2
      [Pipeline] {
      [Pipeline] deleteDir
      [Pipeline] stage
      [Pipeline] { (build)
      [Pipeline] sh
      [withMaven-test2] Running shell script
      + docker pull ubuntu
      Using default tag: latest
      latest: Pulling from library/ubuntu
      Digest: sha256:fbaf303d18563e57a3c1a0005356ad102509b60884f3aa89ef9a90c0ea5d1212
      Status: Image is up to date for ubuntu:latest
      [Pipeline] sh
      [withMaven-test2] Running shell script
      + ls -la /tmp
      total 0
      drwxrwxrwt. 10 root    root    165 Jan  8 13:20 .
      dr-xr-xr-x. 17 root    root    224 Dec 21 15:18 ..
      drwxrwxrwt.  2 root    root      6 May 30  2017 .font-unix
      drwxr-xr-x.  2 jenkins jenkins  18 Jan  8 09:45 hsperfdata_jenkins
      drwxr-xr-x.  2 root    root     18 Jan  3 11:33 hsperfdata_root
      drwxrwxrwt.  2 root    root      6 May 30  2017 .ICE-unix
      drwxrwxr-x.  2 jenkins jenkins   6 Jan  8 09:45 jna--1712433994
      drwxrwxrwt.  2 root    root      6 May 30  2017 .Test-unix
      drwxrwxrwt.  2 root    root      6 May 30  2017 .X11-unix
      drwxrwxrwt.  2 root    root      6 May 30  2017 .XIM-unix
      [Pipeline] sh
      [withMaven-test2] Running shell script
      + docker inspect -f . ubuntu
      .
      [Pipeline] withDockerContainer
      centos-buildserver-03 does not seem to be running inside a container
      $ docker run -t -d -u 995:991 -v /tmp:/mnt) -w /var/lib/jenkins/workspace/Tests/withMaven_tests/withMaven-test2 -v /var/lib/jenkins/workspace/Tests/withMaven_tests/withMaven-test2:/var/lib/jenkins/workspace/Tests/withMaven_tests/withMaven-test2:rw,z -v /var/lib/jenkins/workspace/Tests/withMaven_tests/withMaven-test2@tmp:/var/lib/jenkins/workspace/Tests/withMaven_tests/withMaven-test2@tmp:rw,z -e ******** -e ******** -e ******** -e ******** -e ******** -e ******** -e ******** -e ******** -e ******** -e ******** -e ******** -e ******** -e ******** -e ******** -e ******** -e ******** -e ******** -e ******** -e ******** -e ******** -e ******** -e ******** -e ******** -e ******** --entrypoint cat ubuntu
      [Pipeline] {
      [Pipeline] sh
      [withMaven-test2] Running shell script
      + ls -la /mnt
      total 0
      drwxr-xr-x. 2 root root  6 Dec  1 21:52 .
      drwxr-xr-x. 1 root root 69 Jan  8 12:21 ..
      [Pipeline] }
      $ docker stop --time=1 78f78432d2b054295462b3439fa8125186d0daa7bc355b3d9eb6719f3cc841ef
      $ docker rm -f 78f78432d2b054295462b3439fa8125186d0daa7bc355b3d9eb6719f3cc841ef
      [Pipeline] // withDockerContainer
      [Pipeline] }
      [Pipeline] // stage
      [Pipeline] }
      [Pipeline] // node
      [Pipeline] End of Pipeline
      Finished: SUCCESS
      

       

      Running similart docker commands, directly on BS as jenkins, the volume is mounted sucessfully.

      docker run --rm -v /tmp:/mnt ubuntu ls -la /mnt
      

      Output:

      [jenkins@centos7-buildserver-03 ~]$ docker run --rm -v /tmp:/mnt ubuntu ls -la /mnt
      total 0
      drwxrwxrwt. 10 root root 165 Jan  8 12:06 .
      drwxr-xr-x.  1 root root  46 Jan  8 12:07 ..
      drwxrwxrwt.  2 root root   6 May 30  2017 .ICE-unix
      drwxrwxrwt.  2 root root   6 May 30  2017 .Test-unix
      drwxrwxrwt.  2 root root   6 May 30  2017 .X11-unix
      drwxrwxrwt.  2 root root   6 May 30  2017 .XIM-unix
      drwxrwxrwt.  2 root root   6 May 30  2017 .font-unix
      drwxr-xr-x.  2  995  991  18 Jan  8 08:45 hsperfdata_jenkins
      drwxr-xr-x.  2 root root  18 Jan  3 10:33 hsperfdata_root
      drwxrwxr-x.  2  995  991   6 Jan  8 08:45 jna--1712433994
      

       

       

            Unassigned Unassigned
            ncosta Nuno Costa
            Votes:
            0 Vote for this issue
            Watchers:
            1 Start watching this issue

              Created:
              Updated:
              Resolved: