Docker:无法导出图像:无法创建图像:无法获取图层 [英] Docker: failed to export image: failed to create image: failed to get layer

查看:282
本文介绍了Docker:无法导出图像:无法创建图像:无法获取图层的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我遇到以下错误:

无法导出图像:无法创建图像:无法获取图层sha256:xxxxxxxxxxxxx:图层不存在

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"]

输出:

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

第二次运行总是有帮助的-错误消失了.我正在构建多个不同的映像(不同的jar),并在不同的目录中使用不同的Dockerfile.但是Dockerfile的内容是相同的.

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

我不想删除该行:应用程序和实体是我的库.如果我删除行,则将第三方库(50mb)与实体(2mb)合并为一层.

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

推荐答案

在多阶段构建中,特定顺序的 COPY 命令会发生此问题.

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

一种解决方法是在 COPY 语句之间添加 RUN true :

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/

似乎可行的另一种方法是使用 BUILDKIT 启动构建,如下所示:

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

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

请参阅: https://github.com/moby/moby/issues/37965

这篇关于Docker:无法导出图像:无法创建图像:无法获取图层的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆