Ana içeriğe atla

ENTRYPOINT and CMD confusion in a nutshell

ENTRYPOINT and CMD confusion in a nutshell

exec form (json form) and shell form in brief
exec: [run.sh] => run.sh (command must be in $path )
shell: run.sh => /bin/sh -c run.sh

ENTRYPOINT exec form [run.sh]
execute whatever written, subsequent keywords become params to this executable => run.sh
ENTRYPOINT shell from run.sh
execute the script with prefixing with /bin/sh -c. so it becomes => /bin/sh -c run.sh

CMD 

if there is an ENTRYPOINT defined then this CMD become parameter only. unless ENTRYPOINT defined as shell from which makes CMD ignored.
  • no ENTRYPOINT + CMD [run.sh hello] => /bin/sh -c run.sh hello
  • ENTRYPOINT shell form run.sh hello + CMD exec/shell from => /run.sh (be careful the this command is in the path location ) (notice that CMD is ignoed in this case)
  • ENTRYPOINT exec form [run.sh, hello] + CMD exec form [run.sh ,hello2] => run.sh hello run.sh hello2 (notice that second run.sh is a param only)
  • ENTRYPOINT exec form [run.sh, hello] + CMD shell form run.sh ,hello2 => run.sh hello /bin/sh -c run.sh hello2 (look weird. is not it. but! openshift is mostly rely on this pattern(not much maybe since json form for CMD is also preferred 🙂 ). s2i ENTRYPOINT is [container-ENTRYPOINT] which is consist of ( exec "$@" ) that makes the result => exec /bin/sh -c CMD

we would always be able to use more complex diagrams 🙂

No ENTRYPOINT
ENTRYPOINT exec_entry p1_entry
ENTRYPOINT [“exec_entry”, “p1_entry”]
No CMD
error, not allowed
/bin/sh -c exec_entry p1_entry
exec_entry p1_entry
CMD [“exec_CMD”, “p1_CMD”]
exec_CMD p1_CMD
/bin/sh -c exec_entry p1_entry
exec_entry p1_entry exec_CMD p1_CMD
CMD [“p1_CMD”, “p2_CMD”]
p1_CMD p2_CMD
/bin/sh -c exec_entry p1_entry
exec_entry p1_entry p1_CMD p2_CMD
CMD exec_CMD p1_CMD
/bin/sh -c exec_CMD p1_CMD
/bin/sh -c exec_entry p1_entry
exec_entry p1_entry /bin/sh -c exec_CMD p1_CMD


pls also do not forget the kubernetes terminology for this :

Description
Docker field name
Kubernetes field name
The command run by the container
ENTRYPOINT
command
The arguments passed to the command
CMD
args

and how the overwrite happens in kubernates based environments

Image ENTRYPOINT
Image CMD
Container command
Container args
Command run
[/ep-1]
[foo bar]
<not set>
<not set>
[ep-1 foo bar]
[/ep-1]
[foo bar]
[/ep-2]
<not set>
[ep-2]
[/ep-1]
[foo bar]
<not set>
[zoo boo]
[ep-1 zoo boo]
[/ep-1]
[foo bar]
[/ep-2]
[zoo boo]
[ep-2 zoo boo]



Yorumlar