Docker: failed to export iamge: failed to create image: failed to get layer
概述
在执行docker多阶构建的时候,偶尔会出现 failed to get layer 的错误
dockerfile
## 仅供参考,不一定触发场景
FROM alpine:latest
WORKDIR /data/release
COPY ./nginx-1.16.1.tar.gz ./
COPY ./test.tar.gz ./
COPY ./test_2.tar.gz ./
COPY ./test_3.tar.gz ./
RUN apk add openssl curl ca-certificates make libffi-dev openssl-dev libtool && tar -zxf ./nginx-1.16.1.tar.gz && cd nginx-1.16.1 && make install
failed to export iamge: failed to create image: failed to get layer
解决
在多结构件镜像的过程中,在某些特殊情况下,会出现该错误, 可通过在错误的COPY之间添加 RUN true 解决
## 仅供参考,不一定触发场景
FROM alpine:latest
WORKDIR /data/release
COPY ./nginx-1.16.1.tar.gz ./
RUN true
COPY ./test.tar.gz ./
RUN true
COPY ./test_2.tar.gz ./
RUN true
COPY ./test_3.tar.gz ./
RUN true
RUN apk add openssl curl ca-certificates make libffi-dev openssl-dev libtool && tar -zxf ./nginx-1.16.1.tar.gz && cd nginx-1.16.1 && make install