Docker gotchas ( 1. ENTRYPOINT Vs CMD in Dockerfile)

Well, most of the folks are really confused about the difference between ENTRYPOINT and CMD, so you.
Its simple. Whatever you fill in CMD will be given to the ENTRYPOINT as an argument.

For ex: If you have a dockerfile like this.

CMD ["-tupln"]
ENTRYPOINT ["/usr/bin/netstat"]

and when you run the container without any other command ( For ex:#docker run ….. )
The above instruction basically make it something like “netstat -tulpn” for the container to execute.
Also there is a default entrypoint for each container which is nothing but “/bin/sh -c”
. However note that, the CMD used at end of the ” #docker run … .. ” will overwrite the default command.

You also need to pay some attention on the syntax you use for CMD or ENTRYPOINT. The difference when you use array syntax ( CMD [” “] or shell syntax ( CMD ls -l) is nothing but, if you are not using the array syntax the arguments are prepended with the default entry point which is nothing but “/bin/sh -c”. It may generate unexpected result. So, its always adviceable to use array syntax when using CMD or ENTRYPOINT.

Digiprove sealCopyright secured by Digiprove © 2017 Humble Chirammal

Leave a Reply

Your email address will not be published. Required fields are marked *