I have read somewhere that the hello-world docker image is from scratch so it doesn't have a shell then how it is executing the hello
executable file ? Don't we need a shell to execute a file ?
Asked
Active
Viewed 616 times
0

Sandipan
- 683
- 8
- 25
-
Commands are run in the linux kernel usually using [exec family of functions](http://man7.org/linux/man-pages/man3/exec.3.html) so you don't need a shell. Similar question [How does Docker run a command without invoking a command shell?](https://stackoverflow.com/q/42257450/8482479) – b0gusb Nov 29 '19 at 07:44
-
`Don't we need a shell to execute a file ?` - "shell", by itself, is a executable file. You don't need shell to execute the file. Just execute it instead of the shell. – KamilCuk Nov 29 '19 at 07:46
1 Answers
1
Because the docker CMD
is designed to run executable.
CMD
The CMD instruction has three forms:
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)
There can only be one CMD instruction in a Dockerfile. If you list more than one CMD then only the last CMD will take effect.
The main purpose of a CMD is to provide defaults for an executing container. These defaults can include an executable, or they can omit the executable, in which case you must specify an ENTRYPOINT instruction as well.
So CMD and entrypoint run executable you do not need shell. you will get same response if you run
docker run -it --entrypoint ./hello --rm hello-world
docker run -it --rm hello-world

Adiii
- 54,482
- 7
- 145
- 148