您如何基于遇到的第一个错误取消构建的dockerfile映像? [英] How do you do cancel a dockerfile image building on the first error it encounters?
本文介绍了您如何基于遇到的第一个错误取消构建的dockerfile映像?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
如果我的dockerfile中的RUN命令出错,它将继续执行下一个命令。
If I have an error in a RUN command in my dockerfile it just carries on to the next one.
推荐答案
是您确定命令确实返回了错误?以下Dockerfile不会进入 echo foo
:
Are you sure the command is really returning an error? The following Dockerfile doesn't get to the echo foo
:
FROM alpine
RUN false
RUN echo foo
它只会得到:
# docker build .
Sending build context to Docker daemon 3.072 kB
Step 0 : FROM alpine
---> 0a3b5ba3277d
Step 1 : RUN false
---> Running in 22485c5e763c
The command '/bin/sh -c false' returned a non-zero code: 1
要检查命令是否真的失败,可以尝试执行以下操作:
To check whether your command is really failing, you could try something like this:
FROM alpine
RUN false || echo failed
RUN echo foo
然后得到我:
# docker build .
Sending build context to Docker daemon 3.072 kB
Step 0 : FROM alpine
---> 0a3b5ba3277d
Step 1 : RUN false || echo failed
---> Running in 674f09ae7530
failed
---> 232fd66c5729
Removing intermediate container 674f09ae7530
Step 2 : RUN echo foo
---> Running in c7b541fdb15c
foo
---> dd1bece67e71
Removing intermediate container c7b541fdb15c
Successfully built dd1bece67e71
这篇关于您如何基于遇到的第一个错误取消构建的dockerfile映像?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文