shell格式
RUN apt-get install -y vim
CMD echo "docker so easy"
ENTRYPOINT echo "docker so easy"
Exec格式
RUN ["apt-get","install","-y","vim"]
CMD ["echo","docker so easy"]
ENTRYPOINT ["echo","docker so easy"]
通过两个dockerfile来对比
[root@localhost test]# cat dockerfile1/Dockerfile from centos ENV name Docker ENTRYPOINT echo "$name so easy" [root@localhost test]# cat dockerfile2/Dockerfile from centos ENV name Docker ENTRYPOINT ["/bin/echo","$name so easy"]
[root@localhost test]# pwd /test [root@localhost test]# mkdir dockerfile1 [root@localhost test]# mkdir dockerfile2 [root@localhost test]# vim dockerfile1/Dockerfile [root@localhost test]# cp dockerfile1/Dockerfile dockerfile2/ [root@localhost test]# vim dockerfile2/Dockerfile [root@localhost test]# cat dockerfile1/Dockerfile from centos ENV name Docker ENTRYPOINT echo "$name so easy" [root@localhost test]# cat dockerfile2/Dockerfile from centos ENV name Docker ENTRYPOINT ["/bin/echo","$name so easy"] [root@localhost test]# docker build -t bigni/centos_shell ./dockerfile1/ Sending build context to Docker daemon 2.048kB Step 1/3 : from centos ---> 9f38484d220f Step 2/3 : ENV name Docker ---> Running in 556fd0d58c0f Removing intermediate container 556fd0d58c0f ---> 43e2ff86b0c7 Step 3/3 : ENTRYPOINT echo "$name so easy" ---> Running in d50a776a6a3a Removing intermediate container d50a776a6a3a ---> fc84f5de7f3b Successfully built fc84f5de7f3b Successfully tagged bigni/centos_shell:latest [root@localhost test]# docker build -t bigni/centos_exec ./dockerfile2/ Sending build context to Docker daemon 2.048kB Step 1/3 : from centos ---> 9f38484d220f Step 2/3 : ENV name Docker ---> Using cache ---> 43e2ff86b0c7 Step 3/3 : ENTRYPOINT ["/bin/echo","$name so easy"] ---> Running in 4c226e9e7459 Removing intermediate container 4c226e9e7459 ---> 350ad6186f0b Successfully built 350ad6186f0b Successfully tagged bigni/centos_exec:latest [root@localhost test]# docker image ls -a REPOSITORY TAG IMAGE ID CREATED SIZE bigni/centos_exec latest 350ad6186f0b 10 seconds ago 202MB bigni/centos_shell latest fc84f5de7f3b 41 seconds ago 202MB <none> <none> 43e2ff86b0c7 42 seconds ago 202MB bigni/centos_vim latest f853f2a3f901 2 hours ago 362MB <none> <none> 3ec8199c2855 26 hours ago 861kB bigni/test1 latest f5620b92331c 26 hours ago 861kB ubuntu 14.04 2c5e00d77a67 7 weeks ago 188MB centos latest 9f38484d220f 3 months ago 202MB hello-world latest fce289e99eb9 6 months ago 1.84kB [root@localhost test]# docker run bigni/centos_shell Docker so easy [root@localhost test]# docker run bigni/centos_exec $name so easy [root@localhost test]# vim dockerfile2/Dockerfile [root@localhost test]# cat dockerfile2/Dockerfile from centos ENV name Docker ENTRYPOINT ["/bin/bash","-c","/bin/echo $name so easy"] [root@localhost test]# docker build -t bigni/centos_exec_new ./dockerfile2/ Sending build context to Docker daemon 2.048kB Step 1/3 : from centos ---> 9f38484d220f Step 2/3 : ENV name Docker ---> Using cache ---> 43e2ff86b0c7 Step 3/3 : ENTRYPOINT ["/bin/bash","-c","/bin/echo $name so easy"] ---> Running in c64527904495 Removing intermediate container c64527904495 ---> 6713eb2d0b46 Successfully built 6713eb2d0b46 Successfully tagged bigni/centos_exec_new:latest [root@localhost test]# docker run bigni/centos_exec_new Docker so easy [root@localhost test]#