Dockerfile
ENTRYPOINT and CMD both influence what runs when a container starts. Use ENTRYPOINT for the main executable and CMD for defaults that users can replace.CMD: a replaceable default
docker_snippet
Docker · 2 lines|
| FROM busybox |
| CMD ["echo", "Hello"] |
docker run image uses the default. docker run image echo Goodbye replaces it with the command following the image name.ENTRYPOINT: the main executable
docker_snippet
Docker · 3 lines|
| FROM busybox |
| ENTRYPOINT ["echo"] |
| CMD ["Hello"] |
With no extra arguments, the container runs
echo Hello. docker run image Goodbye replaces CMD and runs echo Goodbye. Override the executable itself with docker run --entrypoint ... when necessary.Exec form and shell form
The exec form uses a JSON array, for example
ENTRYPOINT ["echo"], and starts the program directly. Shell form, such as ENTRYPOINT echo hello, runs through a shell on Linux. Shell form changes argument handling and may prevent the application from receiving signals directly. Prefer exec form when combining ENTRYPOINT with CMD.Only the final
CMD and final ENTRYPOINT instructions in a Dockerfile take effect. Check inherited image configuration when extending an existing image.✦ 卷终 · 柯航存卷 ✦