How Do You Use a Dockerfile with Reserved Words ENTRYPOINT and CMD to Create an Image and Test It Out?

Problem scenario
You want to use the ENTRYPOINT and CMD keywords in a Dockerfile.  You know that the value of CMD amounts to a parameter for the ENTRYPOINT value which is executed.  You want to verify that the value of ENDPOINT is used in an execution.  You want the Dockerfile to be simple to illustrate these reserved words.  What do you do?

Install Docker.  See this posting if you need directions.

1.  Create a file called Dockerfile.  Have these three lines be the content:

FROM ubuntu:latest
CMD ["parameter1 parameter2"]

2.  Run this command:  docker build .

3.  The above command should say something like this:  "Successfully build abcd1234"
The "abcd1234" is the image ID.  Run this next command, but replace "abcd1234" with the image ID that you just created:

docker run abcd1234

# This command above should print "parameter1 parameter2".  

You are done.  That should demonstrate how ENTRYPOINT values use the CMD values as parameters.  In the Dockerfile when you use "docker run" with an image that was the result of a Dockerfile with ENTRYPOINT and CMD stanzas, there will be execution of ENTRYPOINT with one or more additional parameters if CMD is also used.  

Leave a comment

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