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

∥☆過路亽.° 提交于 2021-02-07 12:18:42

问题


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).


回答1:


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

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




回答2:


I received this error, but it didn't tell me anything. If you want it to output the actual error, use this:

docker-compose -f "docker-compose.yml" up --remove-orphans --force-recreate' <optional service: e.g. "nginx">

From:

ERROR: Service 'nginx' failed to build: failed to export image: failed to create image: failed to get layer sha256:63d3...: layer does not exist

To:

Creating project_nginx ... done
Attaching to project_nginx
nginx_1 | 2019/06/12 03:27:30 [emerg] 1#1: BIO_new_file("/etc/ssl/certs/dhparam.pem") failed (SSL: error:02001002:system library:fopen:No such file or directory:fopen('/etc/ssl/certs/dhparam.pem','r') error:2006D080:BIO routines:BIO_new_file:no such file)

From there I could track down the actual issue. But, from the original error, you have no way of knowing what actually caused the failure.



来源:https://stackoverflow.com/questions/51115856/docker-failed-to-export-image-failed-to-create-image-failed-to-get-layer

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!