FROM nginx:latest
COPY ./default.conf /etc/nginx/conf.d/default.conf
location / {
root /usr/share/nginx/html;
index index.html index.htm;
deny all;
}
docker build -t nginx:20220426 .
为什么 CMD ["nginx" "-g" "daemon off;"]在前, COPY ./default.conf /etc/nginx/conf.d/default.conf 在后, 但配置中的 deny all; 依然生效. 谢谢
1
GopherDaily 2022-04-26 23:27:10 +08:00
https://docs.docker.com/engine/reference/builder/#cmd
There can only be one CMD instruction in a Dockerfile. If you list more than one CMD then only the last CMD will take effect. The main purpose of a CMD is to provide defaults for an executing container. These defaults can include an executable, or they can omit the executable, in which case you must specify an ENTRYPOINT instruction as well. 类似 Python 的变量声明,语句可以应用语句之后声明的变量,因为编译时会统一把变量声明提到前面去 |
2
ch2 2022-04-27 01:02:40 +08:00 via iPhone
CMD 表示的是 docker run 或者 start 运行时执行的命令,在构建的时候放在哪无任何区别
|
3
wd 2022-04-27 07:39:19 +08:00 via iPhone
你没弄明白 build 和 run 的区别...
|
4
vonsy OP |