请教一个 docker 打包的问题

2022-04-26 23:22:19 +08:00
 vonsy

Dockerfile

FROM nginx:latest
COPY ./default.conf /etc/nginx/conf.d/default.conf

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; 依然生效. 谢谢

1387 次点击
所在节点    Docker
4 条回复
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 的变量声明,语句可以应用语句之后声明的变量,因为编译时会统一把变量声明提到前面去
ch2
2022-04-27 01:02:40 +08:00
CMD 表示的是 docker run 或者 start 运行时执行的命令,在构建的时候放在哪无任何区别
wd
2022-04-27 07:39:19 +08:00
你没弄明白 build 和 run 的区别...
vonsy
2022-04-27 11:11:50 +08:00

这是一个专为移动设备优化的页面(即为了让你能够在 Google 搜索结果里秒开这个页面),如果你希望参与 V2EX 社区的讨论,你可以继续到 V2EX 上打开本讨论主题的完整版本。

https://www.v2ex.com/t/849455

V2EX 是创意工作者们的社区,是一个分享自己正在做的有趣事物、交流想法,可以遇见新朋友甚至新机会的地方。

V2EX is a community of developers, designers and creative people.

© 2021 V2EX