This is the Dockerfile of Docker Ubuntu official image:
FROM scratch
ADD ubuntu-focal-oci-amd64-root.tar.gz /
CMD ["bash"]
Can you please help me clarifying the following:
- What exactly
CMD["bash"]does? I can see no difference by removing it (e.g. by adding in my local Dockerfile:CMD["echo", "hello"]) when starting a container. - The equivalent shell form is
CMD bashorCMD exec bash? - If removing that completely, what is the equivalent
docker execcommand line?
I cannot find any reliable answer despite my thorough search...
CodePudding user response:
When you create an image
FROM scratch, among other things, it has an empty default command, as if you had writtenENTRYPOINT [] CMD []So
CMDthere gives some default command if youdocker run ubuntu. Most images will in fact override thatCMDwith something to run the program built into the derived image.Since that
CMDuses JSON-array syntax, there isn't directly a shell-syntax equivalent of it. The shell syntax automatically inserts ash -cwrapper around whatever command you give it, so these two would be equivalentCMD bash CMD ["/bin/sh", "-c", "bash"]There would not be an equivalent
docker execcommand.docker execis a debugging command that's not normally part of the "build and run an image" workflow. In particular, it does not use theENTRYPOINTorCMDfrom the image at all.
