加入收藏 | 设为首页 | 会员中心 | 我要投稿 李大同 (https://www.lidatong.com.cn/)- 科技、建站、经验、云计算、5G、大数据,站长网!
当前位置: 首页 > 综合聚焦 > 服务器 > 安全 > 正文

Dockerfile CMD shell与exec表单

发布时间:2020-12-16 03:43:17 所属栏目:安全 来源:网络整理
导读:sheller RUN和CMD语句的shell形式和exec形式之间有什么区别. 例如: RUN [ "npm","start" ] VS: RUN npm start EG2: CMD ["python","my_script.py","argument"] VS: CMD python my_script.py argument shell表单和exec表单之间有两个不同之处.根据the doc

sheller RUN和CMD语句的shell形式和exec形式之间有什么区别.

例如:

RUN [ "npm","start" ]

VS:

RUN npm start 

EG2:

CMD ["python","my_script.py","argument"]

VS:

CMD python my_script.py argument 
shell表单和exec表单之间有两个不同之处.根据the documentation,exec形式是优选的形式.这是两个不同之处:

The exec form is parsed as a JSON array,which means that you must use double-quotes (“) around words not single-quotes (‘).

Unlike the shell form,the exec form does not invoke a command shell. This means that normal shell processing does not happen. For example,CMD [ “echo”,“$HOME” ] will not do variable substitution on $HOME. If you want shell processing then either use the shell form or execute a shell directly,for example: CMD [ “sh”,“-c”,“echo $HOME” ]. When using the exec form and executing a shell directly,as in the case for the shell form,it is the shell that is doing the environment variable expansion,not docker.

这里还有一些细微之处:

The exec form makes it possible to avoid shell string munging,and to RUN commands using a base image that does not contain the specified shell executable.

In the shell form you can use a (backslash) to continue a single RUN instruction onto the next line.

CMD还有第三种形式:

CMD [“param1″,”param2”] (as default parameters to ENTRYPOINT)

此外,如果您将其用作要覆盖的ENTRYPOINT的参数/参数,则CMD需要该exec表单.

(编辑:李大同)

【声明】本站内容均来自网络,其相关言论仅代表作者个人观点,不代表本站立场。若无意侵犯到您的权利,请及时与联系站长删除相关内容!

    推荐文章
      热点阅读