Reputation: 1580
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?
Upvotes: 5
Views: 8573
Reputation: 363063
There is not much difference in your simple example, but there will be a difference if you need shell features such as variable substitution e.g. $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.
Upvotes: 5