试了一下,另一个方案,没深入研究
文件如下
```
FROM ubuntu:20.04
WORKDIR /root
RUN touch 1.txt && exit 1
```
这个 dockerfile 打包会失败,输出如下
[+] Building 2.6s (6/6) FINISHED
=> [internal] load build definition from Dockerfile 0.0s
=> => transferring dockerfile: 101B 0.0s
=> [internal] load .dockerignore 0.0s
=> => transferring context: 2B 0.0s
=> [internal] load metadata for
docker.io/library/ubuntu:20.04 2.0s
=> [1/3] FROM
docker.io/library/ubuntu:20.04@sha256:669e010b58baf5beb2836b253c1fd5768333f0d1dbcb834f7c07a4dc93f474be 0.0s
=> CACHED [2/3] WORKDIR /root 0.0s
=> ERROR [3/3] RUN touch 1.txt && exit 1
此时执行
docker rum --rm -it 709faeff4e2faa40d4bf2a076493bd1e4945a435d55b390427bd358e8e27efeb bash
可以进入[1/3]那步所在的文件层,看到 1.txt 。
root@d89352d51fc5:~# ls
1.txt