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

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

Leave a Comment

Hata!: SQLSTATE[HY000] [1045] Access denied for user 'divattrend_liink'@'localhost' (using password: YES)