RUN
、CMD
和ENTRYPOINT
RUN
执行命令并建立新的Image LayerCMD
设置容器启动后默认执行的命令和参数ENTRYPOINT
设置容器启动时运行的命令EXECdocker
FROM debian RUN ['apt-get','install','-y','vim'] CMD ['/bin/echo','hello world!!'] ENTRYPOINT ['/bin/echo','hello world!!']
SHELLshell
FROM debian RUN apt-get install -y vim CMD echo 'hello world!!' ENTRYPOINT echo 'hello world!!'
apt-get update && apt-get install -y
须要放在同一个RUN
命令中,不然apt-get install
会从缓存中安装软件,致使apt-get update
执行毫无心义apt-get install
的软件尽可能一个一行而且按照字母顺序排列,这样能够避免安装重复的命令apt-get install
安装软件时能够为软件指定特定的版本apt-get install -y aufs-tools s3cmd=1.1.*
CMDvim
ENTRYPOINT缓存
COPY ./script/test.sh /usr/local/bin ENTRYPOINT ['test.sh']