Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Docker: failed to export image: failed to create image: failed to get layer

I got the following error:

failed to export image: failed to create image: failed to get layer sha256:xxxxxxxxxxxxx: layer does not exist

Dockerfile:

FROM openjdk:8
COPY ./lib/ /usr/src/app/BOOT-INF/lib/
COPY ./lib/entities-1.0-SNAPSHOT.jar /usr/src/app/BOOT-INF/lib/entities-1.0-SNAPSHOT.jar
COPY ./app/ /usr/src/app/
WORKDIR /usr/src
CMD ["java", "-cp", "app/", "org.springframework.boot.loader.JarLauncher"]

Output:

Step 3/6 : COPY ./lib/entities-1.0-SNAPSHOT.jar /usr/src/entities-1.0-SNAPSHOT.jar
 ---> 3acb1f6c911a
Step 4/6 : COPY ./app.jar /usr/src/app.jar
failed to export image: failed to create image: failed to get layer sha256:33a94c44f7804ae3f57b9e72f94323c15cef7267be7eb95d90d2a1673c4b33b9: layer does not exist

Second run always helps - error disappears. I'm building multiple different images (different jars), with different Dockerfiles in different directories. But content of Dockerfiles is the same.

I think this error appeared after I add:

COPY ./lib/entities-1.0-SNAPSHOT.jar /usr/src/app/BOOT-INF/lib/entities-1.0-SNAPSHOT.jar

I don't want to remove that row: app and entities is my libs. If I remove row - I'll got one layer with thirdparty libs (50mb) merged with entities (2mb).

like image 223
Lewik Avatar asked Jun 30 '18 14:06

Lewik


1 Answers

This problem occurs with a specific sequence of COPY commands in a multistage build.

More precisely, the bug triggers when there is a COPY instruction producing null effect (for example if the content copied is already present in the destination, with 0 diff), followed immediately by another COPY instruction.

A workaround could be to add RUN true between COPY statements:

COPY ./lib/ /usr/src/app/BOOT-INF/lib/
RUN true
COPY ./lib/entities-1.0-SNAPSHOT.jar /usr/src/app/BOOT-INF/lib/entities-1.0-SNAPSHOT.jar
RUN true
COPY ./app/ /usr/src/app/

Another way that seems to work is to launch the build using BUILDKIT, like that:

DOCKER_BUILDKIT=1 docker build --tag app:test .

See: https://github.com/moby/moby/issues/37965

like image 62
veben Avatar answered Nov 07 '22 00:11

veben