欧卡2中文社区

 找回密码
 立即注册

QQ登录

只需一步,快速开始

需要三步,才能开始

只需两步,慢速开始

欧卡2入门方向盘选莱仕达V9莱仕达折叠便携游戏方向盘支架欢迎地图Mod入驻
查看: 5712|回复: 1
收起左侧

[容器] Dockerfile中CMD和ENTRYPOINT的区别是什么

[复制链接]
丶纠结灬 发表于 2020-5-28 22:57 | 显示全部楼层 |阅读模式
11金币
Dockerfile中CMD和ENTRYPOINT的区别是什么

最佳答案

查看完整内容

[md] ## CMD > The main purpose of a CMD is to provide defaults for an executing container. These defaults can include an executable, or they can omit the executable, in which case you must specify an ENTRYPOINT instruction as well. ``` The CMD instruction has three forms: CMD ["executable","param1","param2"] (exec form, this is the preferred form) CMD ["param1","param2"] (as default par ...
百看不厌 发表于 2020-5-28 22:57 | 显示全部楼层

CMD

The main purpose of a CMD is to provide defaults for an executing container. These defaults can include an executable, or they can omit the executable, in which case you must specify an ENTRYPOINT instruction as well.

The CMD instruction has three forms:

CMD ["executable","param1","param2"] (exec form, this is the preferred form)
CMD ["param1","param2"] (as default parameters to ENTRYPOINT)
CMD command param1 param2 (shell form)

ENTRYPOINT

An ENTRYPOINT allows you to configure a container that will run as an executable.

ENTRYPOINT has two forms:

ENTRYPOINT ["executable", "param1", "param2"] (exec form, preferred)
ENTRYPOINT command param1 param2 (shell form)

简单来说,ENTRYPOINT 是正统地用于定义容器启动以后的执行体的,是容器的 “入口”,CMD 用来定义容器的默认的可执行体,即 docker run 不加执行命令时默认使用 CMD 里定义的可执行体。另外,CMD 还可以用来为 ENTRYPOINT 提供默认参数。

一般还是会用entrypoint的中括号形式作为docker 容器启动以后的默认执行命令,里面放的是不变的部分,可变部分比如命令参数可以使用cmd的形式提供默认版本,也就是run里面没有任何参数时使用的默认参数。如果我们想用默认参数,就直接run,否则想用其他参数,就run 里面加参数


回复 打印

使用道具 举报

您需要登录后才可以回帖 登录 | 立即注册

本版积分规则

联系我们|手机版|欧卡2中国 ( 湘ICP备11020288号-1 )

GMT+8, 2024-11-25 13:12 , Processed in 0.085358 second(s), 10 queries , Redis On.

Powered by Discuz! X3.4

Copyright © 2001-2023, Tencent Cloud.

快速回复 返回顶部 返回列表