问题
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