Docker build image COPY failed: stat no such file or directory

we want to build a backend, based on micronaut framework (java) with jenkins and docker.

Locally all works fine. But not via jenkins/docker.

Error message

During the build of the image the follwing error occurs:

Step 7/11 : COPY --from=build ./build/layers/libs /home/app/libs
COPY failed: stat /var/lib/docker/overlay2/33b475c0bb868e9d61905995e0bd720a30cfde48e7e28acbb31a8a0d88474e24/merged/build/layers/libs: no such file or directory

Dockerfile

FROM gradle:7.2.0-jdk16 as build
WORKDIR /app
COPY --chown=gradle:gradle . /app
RUN gradle build --no-daemon

FROM openjdk:16-alpine
WORKDIR /home/app
COPY --from=build /app/build/layers/libs /home/app/libs
COPY --from=build /app/build/layers/resources /home/app/resources
COPY --from=build /app/build/layers/application.jar /home/app/application.jar
EXPOSE 8080
ENTRYPOINT ["java", "-jar", "/home/app/application.jar"]

Jenkinsfile snippet

stage('Backend: Build Docker image') {
    steps {
        script {
            if (env.BRANCH_NAME == 'master' || env.BRANCH_NAME == 'pipeline') {
                docker.withServer("${dockerServer}") {
                    docker.withRegistry("https://${dockerRegistry}", 'ci-bot-docker') {
                        dir ("backend") {
                            def image = docker.build("${dockerRegistry}/product/${env.BRANCH_NAME}/backend:latest", "-f Dockerfile .")
                            image.push()
                        }
                    }
                }
            }
        }
    }
}

I tried to move the build with gradle from Dockerfile to Jenkinsfile as a separate step. Same error occurs. I searched around and found solutions which also not help.

Can you help me please to fix this :)

bg

Sebastian

1 answer

  • answered 2021-09-23 15:33 Pace17881

    the cause were wrong paths.

    The right paths are:

    COPY --from=builder /app/build/docker/layers/libs /home/app/libs
    COPY --from=builder /app/build/docker/layers/resources /home/app/resources
    COPY --from=builder /app/build/docker/layers/application.jar /home/app/application.jar
    

How many English words
do you know?
Test your English vocabulary size, and measure
how many words do you know
Online Test
Powered by Examplum