Day2: 3.Write example docker file 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

docker file with 2 CMD, 2 ENTRYPOINT

dockerfile6

	FROM ubuntu
	MAINTAINER Anoop << anoop@abc.com>>
	ENV DEBIAN_FRONTEND=noninteractive
	RUN apt-get update 
	RUN apt-get -y install tzdata
	RUN apt-get install git -y && apt-get install -yq apache2
	CMD echo "CMD_Hello_world_1" 
	CMD echo "CMD_Hello_world_2" 
	ENTRYPOINT ["/bin/echo", "ENTRY_Hello_1"]
	ENTRYPOINT ["/bin/echo", "ENTRY_Hello_2"]
		root@ip-172-31-28-155:/tmp/anoop# docker build -f dockerfile6 -t anoop_docker6_1 .
		Sending build context to Docker daemon  7.168kB
		Step 1/10 : FROM ubuntu
		 ---> fb52e22af1b0
		Step 2/10 : MAINTAINER Anoop << anoop@abc.com>>
		 ---> Using cache
		 ---> d127f9a0f32d
		Step 3/10 : ENV DEBIAN_FRONTEND=noninteractive
		 ---> Using cache
		 ---> 6294578b4c0d
		Step 4/10 : RUN apt-get update
		 ---> Using cache
		 ---> 0a42707c1dd0
		Step 5/10 : RUN apt-get -y install tzdata
		 ---> Using cache
		 ---> c4305bb2f6f2
		Step 6/10 : RUN apt-get install git -y && apt-get install -yq apache2
		 ---> Using cache
		 ---> 11c892976ccb
		Step 7/10 : CMD echo "CMD_Hello_world_1"
		 ---> Using cache
		 ---> 0d97d714e8ee
		Step 8/10 : CMD echo "CMD_Hello_world_2"
		 ---> Using cache
		 ---> 99b6c1dd58fe
		Step 9/10 : ENTRYPOINT ["/bin/echo", "ENTRY_Hello_1"]
		 ---> Using cache
		 ---> 7319f0f64bd9
		Step 10/10 : ENTRYPOINT ["/bin/echo", "ENTRY_Hello_2"]
		 ---> Using cache
		 ---> aebe16585944
		Successfully built aebe16585944
		Successfully tagged anoop_docker6_1:latest
	- Eventhough how many ENTRYPOINT and CMD, only last one in the docker file is considered
		root@ip-172-31-28-155:/tmp/anoop# docker run -itd --name anoop_docker6_container anoop_docker6_1
		7a041c9fd3300e59413af15b60bea77d882a26fd3ad68443b07aadbd11f78566
		root@ip-172-31-28-155:/tmp/anoop# docker ps -a | grep anoop_docker6
		7a041c9fd330   anoop_docker6_1                "/bin/echo ENTRY_Hel…"    59 seconds ago      Exited (0) 58 seconds ago                                                anoop_docker6_container
		root@ip-172-31-28-155:/tmp/anoop# docker logs 7a041c9fd330
		ENTRY_Hello_2 /bin/sh -c echo "CMD_Hello_world_2"
	- Tried to change pid1	--> CMD in docker layer is replaced with given command as part of "docker run"

		root@ip-172-31-28-155:/tmp/anoop# docker run --name anoop_docker6_container_1 anoop_docker6_1 git --version
		ENTRY_Hello_2 git --version
		root@ip-172-31-28-155:/tmp/anoop# docker ps -a | grep anoop_docker6
		dc5cbfae4db3   anoop_docker6_1                "/bin/echo ENTRY_Hel…"    6 seconds ago        Exited (0) 5 seconds ago                                                  anoop_docker6_container_1
		7a041c9fd330   anoop_docker6_1                "/bin/echo ENTRY_Hel…"    2 minutes ago        Exited (0) 2 minutes ago                                                  anoop_docker6_container
				

docker file with 1 CMD, 1 ENTRYPOINT

dockerfile5
	FROM ubuntu
	MAINTAINER Rajesh Kumar << rajesh@scmgalaxy.com>>
	ENV DEBIAN_FRONTEND=noninteractive
	RUN apt-get update 
	RUN apt-get -y install tzdata
	RUN apt-get install git -y && apt-get install -yq apache2
	CMD echo "Hello world" 
	ENTRYPOINT ["/bin/echo", "Hello"]
		root@ip-172-31-28-155:/tmp/anoop# docker build -f dockerfile5 -t anoop_docker5 .
		Sending build context to Docker daemon  6.144kB
		Step 1/8 : FROM ubuntu
		 ---> fb52e22af1b0
		Step 2/8 : MAINTAINER Rajesh Kumar << rajesh@scmgalaxy.com>>
		 ---> Using cache
		 ---> 01477b86dfc8
		Step 3/8 : ENV DEBIAN_FRONTEND=noninteractive
		 ---> Using cache
		 ---> 57a1ad7c1cea
		Step 4/8 : RUN apt-get update
		 ---> Using cache
		 ---> 1207d5f945f3
		Step 5/8 : RUN apt-get -y install tzdata
		 ---> Using cache
		 ---> e99c418f5399
		Step 6/8 : RUN apt-get install git -y && apt-get install -yq apache2
		 ---> Using cache
		 ---> a10251de0aa1
		Step 7/8 : CMD echo "Hello world"
		 ---> Using cache
		 ---> da7318408c65
		Step 8/8 : ENTRYPOINT ["/bin/echo", "Hello"]
		 ---> Using cache
		 ---> 95fd2176a9d8
		Successfully built 95fd2176a9d8
		Successfully tagged anoop_docker5:latest
	- Entry point in the last statement of docker layer is worked first and CMD instrcution is considered as argument

		root@ip-172-31-28-155:/tmp/anoop# docker images | grep anoop_docker5
		anoop_docker5                     latest     95fd2176a9d8   About an hour ago    259MB
		root@ip-172-31-28-155:/tmp/anoop# docker run -itd --name anoop_docker5_container anoop_docker5
		e48bf86c3251636b15cab89dae573ad8fae8e9ac5f36f61b9f5eaf0dede82f44
		root@ip-172-31-28-155:/tmp/anoop# docker ps | grep anoop_docker5_container
		root@ip-172-31-28-155:/tmp/anoop# docker ps -a | grep anoop_docker5_container
		e48bf86c3251   anoop_docker5                 "/bin/echo Hello /bi…"    17 seconds ago      Exited (0) 16 seconds ago                                                anoop_docker5_container
		root@ip-172-31-28-155:/tmp/anoop# docker logs e48bf86c3251
		Hello /bin/sh -c echo "Hello world"
		root@ip-172-31-28-155:/tmp/anoop#
			
			
		root@ip-172-31-28-155:/tmp/anoop# docker run --name anoop_docker5_container_1 anoop_docker5
		Hello /bin/sh -c echo "Hello world"
		root@ip-172-31-28-155:/tmp/anoop# docker ps -a | grep anoop_docker5_container
		cd4e95c49666   anoop_docker5                 "/bin/echo Hello /bi…"    4 seconds ago       Exited (0) 3 seconds ago                                                 anoop_docker5_container_1
		e48bf86c3251   anoop_docker5                 "/bin/echo Hello /bi…"    3 minutes ago       Exited (0) 3 minutes ago                                                 anoop_docker5_container
	- Tried to change pid1	--> CMD in docker layer is replaced with given command as part of "docker run"
	
		root@ip-172-31-28-155:/tmp/anoop# docker run --name anoop_docker5_container_2 anoop_docker5 git --version
		Hello git --version
		root@ip-172-31-28-155:/tmp/anoop# docker ps -a | grep anoop_docker5_container
		d9ffb519588d   anoop_docker5                 "/bin/echo Hello git…"    48 seconds ago       Exited (0) 47 seconds ago                                                anoop_docker5_container_2
		cd4e95c49666   anoop_docker5                 "/bin/echo Hello /bi…"    About a minute ago   Exited (0) About a minute ago                                            anoop_docker5_container_1
		e48bf86c3251   anoop_docker5                 "/bin/echo Hello /bi…"    5 minutes ago        Exited (0) 5 minutes ago                                                 anoop_docker5_container