1.CMD
|
|
如:CMD ["/bin/echo", "this is a echo test"]
, docker run: docker run imagename
后输出: this is a echo test
docker run命令如果指定了参数会把CMD里的参数覆盖
如:docker run imagename /bin/bash
, 就不会输出:this is a echo test,因为CMD命令被”/bin/bash”覆盖了
2.ENTRYPOINT
|
|
如:ENTRYPOINT ["/bin/echo"]
,那么build出来的镜像以后的容器功能就像一个/bin/echo程序docker run -it imagename "this is a test"
就等于/bin/echo "this is a test"
注:
1.ENTRYPOINT有两种写法,第二种(shell form)会屏蔽掉docker run时后面加的命令和CMD里的参数。
2.Dockerfile中同时有ENTRYPOINT和CMD,是将CMD当参数传入ENTRYPOINT
3.Demo
Dockefile
run.sh
entypoint.sh
Biuld && Run
1.当ENTRYPOINT ["/entypoint.sh"]
和CMD ["/run.sh"]
,输出结果:
2.当ENTRYPOINT /entypoint.sh
和CMD ["/run.sh"]
,输出结果:
3.当ENTRYPOINT ["/entypoint.sh"]
和CMD /run.sh
,输出结果: