What are shell form and exec form of commands?
I have gone through several documents to get a clear idea of shell form and exec form. But all looked confusing to me. Can anyone help to figure out what are the difference between these two form?
PS: Although I came across these terms while I was going through the docker file instructions(ex: RUN, CMD, ENTRYPOINT
), I want to know the difference between them in general, not in docker context.
Shell form:Commands are written without [] brackets and are run by the container's shell, such as /bin/sh -c . Example: FROM alpine:latest # /bin/sh -c 'echo $HOME' RUN echo $HOME # /bin/sh -c 'echo $PATH' CMD echo $PATH.
Description. The docker exec command runs a new command in a running container. The command started using docker exec only runs while the container's primary process ( PID 1 ) is running, and it is not restarted if the container is restarted. COMMAND will run in the default directory of the container.
Differences between CMD & ENTRYPOINT CMD commands are ignored by Daemon when there are parameters stated within the docker run command while ENTRYPOINT instructions are not ignored but instead are appended as command line parameters by treating those as arguments of the command.
Docker ENTRYPOINT In Dockerfiles, an ENTRYPOINT instruction is used to set executables that will always run when the container is initiated. Unlike CMD commands, ENTRYPOINT commands cannot be ignored or overridden—even when the container runs with command line arguments stated.
The docker shell syntax (which is just a string as the RUN
, ENTRYPOINT
, and CMD
) will run that string as the parameter to /bin/sh -c
. This gives you a shell to expand variables, sub commands, piping output, chaining commands together, and other shell conveniences.
RUN ls * | grep $trigger_filename || echo file missing && exit 1
The exec syntax simply runs the binary you provide with the args you include, but without any features of the shell parsing. In docker, you indicate this with a json formatted array.
RUN ["/bin/app", "arg1", "arg2"]
The advantage of the exec syntax is removing the shell from the launched process, which may inhibit signal processing. The reformatting of the command with /bin/sh -c
in the shell syntax may also break concatenation of your entrypoint and cmd together.
The entrypoint documentation does a good job covering the various scenarios and explaining this in more detail.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With