0

I was trying to run docker save after build to store my docker image in a .tar file

snippet of script.sh:

#build new docker image
$docker build -f Dockerfile -t "$module":$imageversion .

#creating a copy
$docker save "$module":$imageversion > "$module".tar
ls -al

I am running the above script in parallel steps to build my modules concurrently:

Jenkinsfile:

pipeline {
    agent {
        label 'DOCKER_BUILD'
    }
    stages {
        stage("Build") {
            parallel {
                stage("Build module foo") {
                    steps {
                        script {
                            sh "chmod +x script.sh"
                            sh """
                               ./script.sh foo 1.0
                            """
                        }
                    }
                }
                stage("Build module bar") {
                    steps {
                        script {
                            sh "chmod +x script.sh"
                            sh """
                               ./script.sh bar 1.0
                            """
                        }
                    }
                }
            }
        }
    }
}

Below is the result:

Step 1/3 : FROM rhel7.5
 ---> 7b875638cfd8
Step 2/3 : COPY foo /
 ---> 03486e60a155
Removing intermediate container 294374c335e2
Step 3/3 : CMD /foo
 ---> Running in b443c0353f03
 ---> 7cf9cea4eb63
Removing intermediate container b443c0353f03
Successfully built 7cf9cea4eb63

Error response from daemon: open /var/lib/docker/devicemapper/mnt/ea79ca596a1bdf10526762edf47ac439e3a54d3d327ee3b19b9d11e589299298/rootfs/root/buildinfo/Dockerfile-rhel7-7.5-433: no such file or directory

    drwxr-xr-x  3 pdcifadm dcifgrp     4096 Jun 13 17:09 .
    drwxr-xr-x 31 pdcifadm dcifgrp     4096 Jun 13 17:05 ..
    -rwxr-xr-x  1 pdcifadm dcifgrp 15370790 Jun 13 17:07 foo
    -rw-r--r--  1 pdcifadm dcifgrp        0 Jun 13 17:09 module-foo.tar
    -rw-r--r--  1 pdcifadm dcifgrp       74 Jun 13 17:07 Dockerfile
    -rwxr-xr-x  1 pdcifadm dcifgrp      105 Jun 13 17:07 script.sh

Notice the .tar file has 0 bytes. I got the same result when I viewed Build module bar logs.

I tried testing more parallel builds and I saw that docker save sometimes works as expected in some steps.

Running the build sequentially is working as expected.

Am I missing something here? Maybe the agent or workspace issues?

Thanks in advance!

Cheers!

sailhenz
  • 1,052
  • 9
  • 22
  • Why are you using a shell script for Docker commands instead of the Pipeline API? This does seem like you are taking a difficult route here. – Matthew Schuchard Jun 13 '19 at 16:51
  • 1
    Sounds like a docker issue, not jenkins related. Some race condition, with parallel building of same image. Check out [this](https://github.com/kubernetes/kubernetes/issues/40632) github issue, there are some steps mentioned to reduce the probability of occurrence, i.e. configuring different storage drivers, i.e. [here](https://docs.docker.com/storage/storagedriver/device-mapper-driver/). If you got the hw, you could run the parallel jobs on different agents too. – Dominik Gebhart Jun 13 '19 at 18:33

0 Answers0