【Docker】Dockerfile 之 ENTRYPOINT(一)
参考教程:https://docs.docker.com/engine/reference/builder/
环境
- virtual box 6.1
- centos 7.8
- docker 19.03
ENTRYPOINT
ENTRYPOINT has two forms:
ENTRYPOINT 有两种形式:
The exec form, which is the preferred form:
exec 形式,这是首选形式:
ENTRYPOINT ["executable", "param1", "param2"]
The shell form:
shell 形式:
ENTRYPOINT command param1 param2
An ENTRYPOINT
allows you to configure a container that will run as an executable.
ENTRYPOINT
允许您配置为容器配置一个可执行的命令。
For example, the following starts nginx with its default content, listening on port 80:
例如,以下代码以其默认内容启动 nginx,监听端口 80:
$ docker run -i -t --rm -p 80:80 nginx
Command line arguments to docker run <image>
will be appended after all elements in an exec form ENTRYPOINT
, and will override all elements specified using CMD
. This allows arguments to be passed to the entry point, i.e., docker run <image> -d
will pass the -d
argument to the entry point. You can override the ENTRYPOINT
instruction using the docker run --entrypoint
flag.
docker run <image>
的命令行参数将以 exec 形式的所有元素添加到 ENTRYPOINT
后面,并将覆盖所有使用 CMD
指定的元素。这允许将参数传递给入口点,即 docker run <image> -d
将参数 -d
传递给入口点。您可以使用 docker run --entrypoint
标志覆盖 ENTRYPOINT
指令。
The shell form prevents any CMD
or run
command line arguments from being used, but has the disadvantage that your ENTRYPOINT
will be started as a subcommand of /bin/sh -c
, which does not pass signals. This means that the executable will not be the container’s PID 1
- and will not receive Unix signals - so your executable will not receive a SIGTERM
from docker stop <container>
.
shell 格式阻止使用任何 CMD
或 run
命令行参数,但具有以下缺点:ENTRYPOINT
将作为 /bin/sh -c
的子命令启动,该子命令不会传递信号。这意味着该可执行文件将不是容器的 PID 1
,并且不会接收 Unix 信号,因此您的可执行文件将不会从 docker stop <container>
接收到 SIGTERM
。
Only the last ENTRYPOINT
instruction in the Dockerfile
will have an effect.
只有 Dockerfile
中的最后一条 ENTRYPOINT
指令才会生效。
总结
介绍了 Dockerfile 中 ENTRYPOINT 指令。
【推荐】国内首个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框架的用法!