Docker build is not stopping on failed run command

十年热恋 提交于 2019-12-11 17:57:22

问题


I have this in a Dockerfile

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

and I see:

The command '/bin/sh -c eval ssh-agent -s && ssh-add /root/.ssh/id_rsa' returned a non-zero code: 1

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?


回答1:


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

Do this:

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

TL;DR: A short example why:

This works until the end:

FROM alpine
RUN exit 0
RUN echo Hello

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


来源:https://stackoverflow.com/questions/55940444/docker-build-is-not-stopping-on-failed-run-command

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!