使用golang开发,需要交叉编译rpm。docker是不二之选,所以编写了golang编译打包镜像。学习并记录下dockerfile语法。
CMD
CMD
CMD ["","","",...]
CMD ["","",...]
eg:
CMD echo 1
CMD ["echo","1"] 或者 CMD ["sh","可执行文件.sh",”参数1“]
CMD ["1","2"] 需要结合entrypoint使用作为参数
ENTRYPOINT
ENTRYPOINT
ENTRYPOINT ["","","",...]
eg:
ENTRYPOINT echo 1
ENTRYPOINT ["echo","1"] 或者 ENTRYPOINT ["sh","可执行文件.sh",”参数1“]
区别
a.CMD与ENTRYPOINT 各自以最后一条生效,语法大致相同
b.CMD可以作为ENTRYPOINT的默认参数
CMD ["默认参数1","默认参数2"]
ENTRYPOINT ["sh","可执行文件.sh"]
docker run ... 该镜像
等同无配置
docker run ... 该镜像 sh -c "可执行文件.sh 默认参数1 默认参数2"
c.CMD 默认参数docker run可覆盖,没有ENTRYPOINT情况可以覆盖执行命令
CMD ["默认参数1","默认参数2"]
ENTRYPOINT ["sh","可执行文件.sh"]
docker run ... 该镜像 test1 test2
等同无配置
docker run ... 该镜像 sh -c "可执行文件.sh test1 test2"
CMD ["sh","可执行文件.sh","默认参数1","默认参数2"]
docker run ... 该镜像 echo test1 test2
等同无配置
docker run ... 该镜像 sh -c "echo test1 test2"
d.ENTRYPOINT可以使用 --entrypoint
CMD ["默认参数1","默认参数2"]
ENTRYPOINT ["sh","可执行文件.sh"]
docker run --entrypoint echo ... 该镜像
等同无配置
docker run ... 该镜像 sh -c "echo test1 test2"
CMD ["默认参数1","默认参数2"]
ENTRYPOINT ["sh","可执行文件.sh"]