Just I would like to know if there is some difference behind the scenes between doing:
CMD echo 'Hello world'
and
CMD ['echo', 'Hello World']
I know that both will print it on the console , but if there is some difference, when use each option?
There is not much difference in your simple example, but there will be a difference if you need shell features such as variable substitution eg $HOME
.
This is the shell form. It will invoke a command shell:
CMD echo 'Hello world'
This is the exec form. It does not invoke a command shell:
CMD ["/usr/bin/echo", "Hello World"]
The exec form is parsed as a JSON array, which means that you should be using double-quotes around words, not single-quotes, and you should give the full path to an executable. The exec form is the preferred format of CMD.
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.