Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

What are shell form and exec form?

Tags:

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.

like image 486
Mufeed Avatar asked Dec 20 '17 11:12

Mufeed


People also ask

What is Shell Form in docker?

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.

What is docker Exec form?

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.

What is difference between CMD and entrypoint?

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.

What is entrypoint in Dockerfile?

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.


1 Answers

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.

like image 127
BMitch Avatar answered Sep 17 '22 15:09

BMitch