V2EX = way to explore
V2EX 是一个关于分享和探索的地方
现在注册
已注册用户请  登录
vonsy
V2EX  ›  Docker

请教一个 docker 打包的问题

  •  
  •   vonsy · 2022-04-26 23:22:19 +08:00 · 1379 次点击
    这是一个创建于 722 天前的主题,其中的信息可能已经有所发展或是发生改变。

    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; 依然生效. 谢谢 docker-build-nginx.png

    4 条回复    2022-04-27 11:11:50 +08:00
    GopherDaily
        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 的变量声明,语句可以应用语句之后声明的变量,因为编译时会统一把变量声明提到前面去
    ch2
        2
    ch2  
       2022-04-27 01:02:40 +08:00 via iPhone
    CMD 表示的是 docker run 或者 start 运行时执行的命令,在构建的时候放在哪无任何区别
    wd
        3
    wd  
       2022-04-27 07:39:19 +08:00 via iPhone
    你没弄明白 build 和 run 的区别...
    关于   ·   帮助文档   ·   博客   ·   API   ·   FAQ   ·   我们的愿景   ·   实用小工具   ·   5433 人在线   最高记录 6543   ·     Select Language
    创意工作者们的社区
    World is powered by solitude
    VERSION: 3.9.8.5 · 36ms · UTC 06:51 · PVG 14:51 · LAX 23:51 · JFK 02:51
    Developed with CodeLauncher
    ♥ Do have faith in what you're doing.