CODE/2022-09-30

Dockerfile ENTRYPOINT vs. CMD

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.
COMPANION ESSAYS / 思想脉络与互照篇目
同卷深读2026-05-22 ·

Installing Python 3 Alongside System Python on CentOS 7

同属「系统工程卷」脉络衍生思考与工程推演推演阅读 →
跨界互照2026-08-22 ·

我的书架:03|金融经管:经济运行、金融体系与企业治理

我的书架:03|金融经管:经济运行、金融体系与企业治理

跨领域对照思辨 · 从「思想随笔」视界互为印证推演阅读 →
RELATED INDEX / 相关阅读索引
柯航hang.ke·© 2014—2026
CC BY-NC 4.0·