Difference between && and `set -ex` in Dockerfiles
This isn't specific to Docker; it's just regular shell syntax used in the RUN
command. set -e
causes the script to exit if any command fails, while &&
only runs its right-hand command if the left-hand command does not fail. So in both
set -efoobar
and
foo && bar
bar
will only run if foo
succeeds.
So, the two are identical if the entire script consists of a single list command ... && ... && ...
where a command only runs if every previous command succeeds. An example of how they would differ:
set -eecho onefalseecho twoecho three
Here, echo two
and echo three
would never run. But in
echo one && false && echo twoecho three
the echo three
would still run, because only echo two
was "guarded" by the &&
preceding it.