The Dockerfile should contain at most one ENTRYPOINT and one CMD instruction, because only the last one will have an
effect.
Multiple ENTRYPOINT or CMD instructions in a file can lead to confusion as we may think they are all applied. This is not
the case, as only the last one is applied.
Previous ENTRYPOINT and CMD instructions should be removed to avoid this.
FROM busybox ENTRYPOINT ignored_entrypoint param1 param2 ENTRYPOINT effective_entrypoint param1 param2 CMD ignored_cmd param1 param2 CMD effective_cmd param1 param2
Here we have multiple ENTRYPOINT and CMD instructions. The first ENTRYPOINT and the first CMD
instructions will have no effect. Although this is valid in Docker, this can lead to confusion and be error-prone, as we may expect each
CMD and ENTRYPOINT to have an effect.
Multi-Stage Build:
FROM scratch as development CMD ignored_scratch_cmd param1 param2 CMD effective_scratch_cmd param1 param2 FROM busybox CMD ignored_busyBox_cmd param1 param2 CMD effective_busyBox_cmd param1 param2
For multi-stage builds we take each stage into account separately. This is because there are valid docker setups, where the file should only be
build up to a certain stage. In the example, the developer builds only the first stage as a development environment via docker build --target
development.
FROM busybox ENTRYPOINT effective_entrypoint param1 param2 CMD effective_cmd param1 param2
Here we have only one ENTRYPOINT and one CMD instruction. Each of them will be considered by the docker container and
have a normal effect, as we can expect.
Multi-Stage Build:
FROM scratch as development CMD effective_scratch_cmd param1 param2 FROM busybox CMD effective_busyBox_cmd param1 param2
For each stage, we only have one CMD or ENTRYPOINT instruction.