DOCKER| ENTRYPOINT vs. CMD

O.K…. Lets start. ;)

ENTRYPOINT will be executed and container arguments will be passed to ENTRYPOINT. If there are no container arguments, then CMD will be passed to the container as the default argument. That means that CMD will be passed to ENTRYPOINT.
If there is no defined ENTRYPOINT, the CMD shifts to the first place.
CMD will be always overridden by CONTAINERARGUMENTS

In fact a command string will be constucted the following way:

THE FOLLOWING EXAMPLES ARE USED FOR DESCRIPTION — IT’S NO CODE

At start the container executes something like

if [ -z $CONTAINERARGUMENTS ]; then
exec $($ENTRYPOINT $CMD)
else
exec $($ENTRYPOINT $CONTAINERARGUMENTS)
fi

In other words:

if [ ! -z $CONTAINERAGUMENTS ]; then
CMD=$CONTAINERAGUMENTS
fi

if [ -z $ENTRYPOINT ]; then
EXECSTRING=”$CMD”
else
EXECSTRING=”$ENTRYPOINT $CMD”
fi

In other other words:

You have three variables: ENTRYPOINT, CMD and CONTAINERARGS

Rule #1: Existing CONTAINERARGS replace CMD
Rule #2: If ENTRYPOINT exists, the string “ENTRYPOINT CMD” will be executed – If ENTRYPOINT does not exist, the string “CMD” will be executed. – If CMD does not exist but ENTRYPOINT, string “ENTRYPOINT” will be executed.

In other other other words:

ENTRYPOINT + CMD => exec $($ENTRYPOINT $CMD)
CMD => exec $($CMD)
ENTRYPOINT + CMD + CONTAINERARGS => exec $($ENTRYPOINT $CONTAINERARGS)
CMD + CONTAINERARGS => exec $($CONTAINERARGS)
ENTRYPOINT + CONTAINERARGS => exec $($ENTRYPOINT $CONTAINERARGS)
ENTRYPOINT => exec $($ENTRYPOINT)
CONTAINERARGS => exec $($CONTAINERARGS)
NOTHING => exec NOTHING

Advertisements

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s