How do you tell Docker to stop executing a Dockefile when one of its RUN commands returns an error code?
I have a Dockerfile like:
FROM ubuntu:18.04
RUN apt install -yq `cat requirements.txt | tr "\\n" " "`
RUN ./some_other_setup.sh
RUN ./my_tests.sh
and occasionally the apt install
will fail if there's a brief network outage. However, the Docker will continue executing the other RUN commands, even though they too will fail because they depend on the apt install
succeeding.
If you want to catch error and stop you can do like linux script
RUN set -e && apt install -yq `cat requirements.txt | tr "\\n" " "`
so set -e
will catch all errors and stop if any happened.
OR
you can prevent failing apt install
by adding RUN apt-get install -f
which will install missing dependencies.
Also if apt-get/apt install
has any errors you can do
apt-get install [your stuff] || true
which will always pass even with errors and then you do apt-get install -f
so you always have all dependencies needed
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With