ENTRYPOINT 和 CMD 都定义了容器启动时运行的内容,但它们扮演不同的角色并以特定方式交互。理解它们的区别(以及两种形式——exec 与 shell)对于编写表现正确的 Dockerfile 很重要。
CMD — 默认命令(可被覆盖)
CMD ["node", "server.js"]
# → the DEFAULT command when the container starts
# → but it's REPLACED if you pass a command at run time:
# docker run myapp echo hello → runs "echo hello" INSTEAD of node server.js
提供,该命令会被 中指定的任何命令。
