Exec vs Shell
So far I have been showing CMD and ENTRYPOINT with a json array ie: CMD [“executable”, “arg1”, “arg2”] This is called the ‘exec’ form and is the Docker prefered form. And if you are using CMD with ENTRYPOINT you must use the ‘exec’ form.
‘shell’ is the alternate form to provide commands and would like: CMD executable arg1 arg2
What are the main differences.
- CMD or ENTRYPOINT ‘shell’ runs within a shell ‘/bin/sh -c’ allowing for environment variable expansion such as
echo $HOME
- ENTRYPOINT using ‘shell’ prevents CMD from being used
- ENTRYPOINT using ‘shell’ is started as a subcommand of ‘/bin/sh -c’ so you need to run your executable with exec to ensure that it is started as PID1