footanna.blogg.se

Docker entrypoint
Docker entrypoint









docker entrypoint

0 # Shell: echoes "1.0.0" because Docker does the substitution RUN echo $VERSION # Exec: echoes "1.0.0" because Docker does the substitution RUN Shell features However, both forms behave the same when it comes to environment variables set by the ENV instruction: FROM alpine:latestĮNV VERSION= 1.0. # Shell: echoes "/root" as set by the shell RUN echo $HOME # Exec: echoes "$HOME" because nothing is set RUN In the shell form, commands will inherit environment variables from the shell, such as $HOME and $PATH: FROM alpine:latest There are real use cases where you may not want to follow the above recommendations, so let's explore the main consequences of the two forms. The general idea is to use the exec form unless you need shell features - and if you need shell features in the ENTRYPOINT or CMD, then consider writing a shell script and executing it with the exec form. CMD: exec form, because of the signal trapping described below.ENTRYPOINT: exec form, because of the signal trapping described below.

docker entrypoint

RUN: shell form, because of the shell features described below.These are the recommended forms to use for each instruction: This removes a potentially extra process in the process tree, which may be desirable. # /bin/sh -c 'echo $HOME' RUN echo $HOME # /bin/sh -c 'echo $PATH' CMD echo $PATHĭepending on the shell, commands will execute as child processes of the shell, which has some potentially negative consequences at the cost of some features, described below.Ĭommands are written with brackets and are run directly, not through a shell. The two formsĬommands are written without brackets and are run by the container's shell, such as /bin/sh -c. The RUN, ENTRYPOINT, and CMD, instructions all have two different forms they can be written in, and those forms change how each of those instructions behaves.











Docker entrypoint