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

DevOps

Upgrade & Secure Your Future with DevOps, SRE, DevSecOps, MLOps!

We spend hours on Instagram and YouTube and waste money on coffee and fast food, but won’t spend 30 minutes a day learning skills to boost our careers.
Master in DevOps, SRE, DevSecOps & MLOps!

Learn from Guru Rajesh Kumar and double your salary in just one year.


Get Started 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.