【Docker】Dockerfile 之 ENTRYPOINT(一)

参考教程:https://docs.docker.com/engine/reference/builder/

环境

  1. virtual box 6.1
  2. centos 7.8
  3. 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 格式阻止使用任何 CMDrun 命令行参数,但具有以下缺点: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 指令。

posted @   jiangbo4444  阅读(1947)  评论(0编辑  收藏  举报
编辑推荐:
· 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框架的用法!
点击右上角即可分享
微信分享提示