When you use 2 CMD commands in docker file the last CMD command will be considered.
eg:
- Write dockerfile with 2 CMD commands:
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"
CMD ls
Building the dockerfile:
[root@localhost docs]# docker build -t aswin1 -f doc38 .
unable to prepare context: unable to evaluate symlinks in Dockerfile path: lstat /root/docs/doc38: no such file or directory
[root@localhost docs]# docker build -t aswin1 -f doc8 .
Sending build context to Docker daemon 10.75kB
Step 1/8 : FROM ubuntu
---> a8780b506fa4
Step 2/8 : MAINTAINER Rajesh Kumar << rajesh@scmgalaxy.com>>
---> Using cache
---> 88f6b6acfa81
Step 3/8 : ENV DEBIAN_FRONTEND=noninteractive
---> Using cache
---> c8a76e7a5f98
Step 4/8 : RUN apt-get update
---> Using cache
---> 4d9fe31bf152
Step 5/8 : RUN apt-get -y install tzdata
---> Using cache
---> 41891c047aab
Step 6/8 : RUN apt-get install git -y && apt-get install -yq apache2
---> Using cache
---> cfaefb036054
Step 7/8 : CMD echo "Hello world"
---> Using cache
---> e3a33016f8d3
Step 8/8 : CMD ls
---> Running in 39af03f7ea29
Removing intermediate container 39af03f7ea29
---> 4ec90f2ffbdf
Successfully built 4ec90f2ffbdf
Successfully tagged aswin1:latest
[root@localhost docs]# docker images
REPOSITORY TAG IMAGE ID CREATED SIZE
aswin1 latest 4ec90f2ffbdf 10 seconds ago 252MBRunning docker run command to create the container:
[root@localhost docs]# docker run -itd aswin1
837cffa37f38494cfdc264bb5da82b4f515834d850f2b23b822971230fe03022
[root@localhost docs]# docker ps -a
CONTAINER ID IMAGE COMMAND CREATED STATUS PORTS NAMES
837cffa37f38 aswin1 "/bin/sh -c ls" 7 seconds ago Exited (0) 6 seconds ago keen_wright
Top comments (0)