Docker构建不会因失败的运行命令而停止

Docker构建不会因失败的运行命令而停止

本文介绍了Docker构建不会因失败的运行命令而停止的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我在Dockerfile中有这个

I have this in a Dockerfile

RUN eval `ssh-agent -s` && ssh-add /root/.ssh/id_rsa

我看到:

,但docker build继续进行,直到到达ENTRYPOINT,然后退出.如果其中一个RUN命令以非零值退出,如何使docker构建过程停止?

but the docker build continues until it reaches the ENTRYPOINT and then exits. How can I get the docker build process to stop if one of the RUN commands exits with non-zero?

推荐答案

Docker不会将run命令的不同部分连接为逻辑AND.它更像是OR

Docker don't connect the different parts of your run command as an logical AND. It is more like a OR

执行此操作:

RUN eval `ssh-agent -s`
RUN ssh-add /root/.ssh/id_rsa


TL; DR:一个简短的例子说明为什么:


TL;DR:A short example why:

这一直持续到最后:

FROM alpine
RUN exit 0
RUN echo Hello

这会在第一个RUN之前停止:

This stops by the first RUN:

FROM alpine
RUN exit 1
RUN echo Hello

此操作一直运行到最后(如您的示例):

This run until the end (like your example):

FROM alpine
RUN exit 0 && exit 1
RUN echo Hello

这篇关于Docker构建不会因失败的运行命令而停止的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!

08-28 19:56