【Docker】Dockerfile 之 ENTRYPOINT(四)
参考教程:https://docs.docker.com/engine/reference/builder/
环境
- virtual box 6.1
- centos 7.8
- docker 19.03
ENTRYPOINT 和 CMD 的交互
Both CMD
and ENTRYPOINT
instructions define what command gets executed when running a container. There are few rules that describe their co-operation.
CMD
和 ENTRYPOINT
指令均定义了运行容器时执行的命令。有少量的规则描述他们的合作。
-
Dockerfile should specify at least one of
CMD
orENTRYPOINT
commands. -
Dockerfile 应该至少指定
CMD
或ENTRYPOINT
命令之一。 -
ENTRYPOINT
should be defined when using the container as an executable. -
使用容器作为可执行文件时,应定义
ENTRYPOINT
。 -
CMD
should be used as a way of defining default arguments for anENTRYPOINT
command or for executing an ad-hoc command in a container. -
应该使用
CMD
作为定义ENTRYPOINT
命令或在容器中执行命令的默认参数的方式。 -
CMD
will be overridden when running the container with alternative arguments. -
当使用其他参数运行容器时,
CMD
将被覆盖。
The table below shows what command is executed for different ENTRYPOINT
/ CMD
combinations:
下表显示了针对不同的 ENTRYPOINT
/CMD
组合执行的命令:
No ENTRYPOINT | ENTRYPOINT exec_entry p1_entry | ENTRYPOINT [“exec_entry”, “p1_entry”] | |
---|---|---|---|
No CMD | error, not allowed | /bin/sh -c exec_entry p1_entry | exec_entry p1_entry |
CMD [“exec_cmd”, “p1_cmd”] | exec_cmd p1_cmd | /bin/sh -c exec_entry p1_entry | exec_entry p1_entry exec_cmd p1_cmd |
CMD [“p1_cmd”, “p2_cmd”] | p1_cmd p2_cmd | /bin/sh -c exec_entry p1_entry | exec_entry p1_entry p1_cmd p2_cmd |
CMD exec_cmd p1_cmd | /bin/sh -c exec_cmd p1_cmd | /bin/sh -c exec_entry p1_entry | exec_entry p1_entry /bin/sh -c exec_cmd p1_cmd |
Note
If
CMD
is defined from the base image, settingENTRYPOINT
will resetCMD
to an empty value. In this scenario,CMD
must be defined in the current image to have a value.
注意
如果从基础镜像定义了
CMD
,则设置ENTRYPOINT
会将CMD
重置为空值。在这种情况下,必须在当前镜像中定义CMD
以具有值。
总结
介绍了 Dockerfile 中 ENTRYPOINT 指令和 CMD 指令的交互。
【推荐】国内首个AI IDE,深度理解中文开发场景,立即下载体验Trae
【推荐】编程新体验,更懂你的AI,立即体验豆包MarsCode编程助手
【推荐】抖音旗下AI助手豆包,你的智能百科全书,全免费不限次数
【推荐】轻量又高性能的 SSH 工具 IShell:AI 加持,快人一步
· SQL Server 2025 AI相关能力初探
· Linux系列:如何用 C#调用 C方法造成内存泄露
· AI与.NET技术实操系列(二):开始使用ML.NET
· 记一次.NET内存居高不下排查解决与启示
· 探究高空视频全景AR技术的实现原理
· 阿里最新开源QwQ-32B,效果媲美deepseek-r1满血版,部署成本又又又降低了!
· 单线程的Redis速度为什么快?
· SQL Server 2025 AI相关能力初探
· AI编程工具终极对决:字节Trae VS Cursor,谁才是开发者新宠?
· 展开说说关于C#中ORM框架的用法!