Write a example dockerfile with 2 CMD, 2 ENTRYPOINT and 1 CMD/1ENTRYPOINT and write down a behaviour of it.

Limited Time Offer!

For Less Than the Cost of a Starbucks Coffee, Access All DevOpsSchool Videos on YouTube Unlimitedly.
Master DevOps, SRE, DevSecOps Skills!

Enroll Now

Dockerfile with 2 CMD, 2 ENTRYPOINT:

File content:

FROM ubuntu
MAINTAINER Sunil << r.s.sunil@gmail.com>>
CMD "World" 
CMD echo "DOCKER"
ENTRYPOINT ["/bin/echo", "Hello"]
ENTRYPOINT ["/bin/echo", "Welcome to"]

Output:

Welcome to /bin/sh -c echo “DOCKER”

Observations:

  • Both CMD and ENTRYPOINT entries will be overwritten with the latest entries.
  • That is only the last CMD and ENTRYPOINT will be taken.
  • Also the values specified in CMD will be add as an argument to the ENTRYPOINT command.

Dockerfile with 1 CMD, 1 ENTRYPOINT:

File content:

FROM ubuntu
MAINTAINER Sunil << r.s.sunil@gmail.com>>
CMD "World" 
ENTRYPOINT ["/bin/echo", "Hello "]

Output:

Hello World

Observations:

  • Values specified in CMD will be add as an argument to the ENTRYPOINT command.