Dockerfile中ENTRYPOINT,CMD 比较
ENTRYPOINT 的两种格式:
- ENTRYPOINT ["executable", "param1", "param2"] (exec格式,推荐使用此格式)
- ENTRYPOINT command param1 param2 (shell 格式)
CMD指令有三种格式:
- CMD ["executable","param1","param2"] (exec 格式,推荐用此格式)
- CMD command param1 param2 (shell 格式)
下图是对比Dockerfile
请将下列代码复制- http://www.mdeditor.com/ 效果展示
<table class="table table-bordered table-striped table-condensed">
<tr>
<td colspan="2">ENTRYPOINT</td>
<td colspan="2">CMD</td>
<td rowspan="2">docker run ... image CMD</td>
<td rowspan="2">运行结果</td>
</tr>
<tr>
<td>exec格式</td>
<td>shell格式</td>
<td>exec格式</td>
<td >shell格式</td>
</tr>
<tr>
<td>√</td>
<td></td>
<td>√</td>
<td></td>
<td></td>
<td><ENTRYPOINT><CMD></td>
</tr>
<tr>
<td>√</td>
<td></td>
<td></td>
<td>√</td>
<td></td>
<td><ENTRYPOINT></td>
</tr>
<tr>
<td></td>
<td>√</td>
<td>√</td>
<td></td>
<td></td>
<td><ENTRYPOINT></td>
</tr>
<tr>
<td></td>
<td>√</td>
<td></td>
<td>√</td>
<td></td>
<td><ENTRYPOINT></td>
</tr>
<tr>
<td>√</td>
<td></td>
<td></td>
<td></td>
<td>√</td>
<td><ENTRYPOINT><CMD></td>
</tr>
<tr>
<td></td>
<td>√</td>
<td></td>
<td></td>
<td>√</td>
<td><ENTRYPOINT></td>
</tr>
<tr>
<td></td>
<td></td>
<td>√</td>
<td></td>
<td>√</td>
<td><Docker run CMD></td>
</tr>
<tr>
<td></td>
<td></td>
<td></td>
<td>√</td>
<td>√</td>
<td><Docker run CMD></td>
</tr>
</table>
注意:
- Dockerfile 中多个CMD 最后一个生效
- shell和exec格式的区别,只有shell形式才会获取相关环境变量(这里环境变量指例如:$HOME)
- Docker run CMD 会覆盖 Dockerfile 中的 CMD
K8s Yaml中command,args
<table class="table table-bordered table-striped table-condensed">
<tr>
<td colspan="2">K8s Yaml</td>
<td colspan="2">Docker</td>
<td rowspan="2">运行结果</td>
</tr>
<tr>
<td>command</td>
<td>args</td>
<td>ENTRYPOINT</td>
<td>CMD</td>
</tr>
<tr>
<td></td>
<td></td>
<td>√</td>
<td>√</td>
<td>按照docker规则</td>
</tr>
<tr>
<td>√</td>
<td></td>
<td>√ | x</td>
<td>√ | x</td>
<td><command>没有参数</td>
</tr>
<tr>
<td></td>
<td>√</td>
<td>√</td>
<td></td>
<td><ENTRYPOINT><args></td>
</tr>
<tr>
<td>√</td>
<td>√</td>
<td>√ | x</td>
<td>√ | x</td>
<td><command><args></td>
</tr>
</table>
备注:
- | 表示或
- x 表示空
- √ 表示有
网友评论