Reputation: 23
I have been studying Dockerfile
implementations of several projects and I noticed that some of them start the application with:
CMD executable
while other do:
CMD /bin/sh -c "executable"
I have been trying both versions for each project, and don't really notice a difference.
Is there a difference? If so, when is which version preferred?
Upvotes: 2
Views: 3550
Reputation: 1618
From the docker documentation (https://docs.docker.com/engine/reference/builder/):
- 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)
...
Note: 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.
So
CMD executable
which uses the shell form is already implicitly invoking a shell. So there's no reason to explicit invoke one.
Upvotes: 2