vonsy
V2EX  ›  Docker

请教一个 docker 打包的问题

  •  
  •   vonsy · Apr 26, 2022 · 2399 views
    This topic created in 1655 days ago, the information mentioned may be changed or developed.

    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 replies  •  2022-04-27 11:11:50 +08:00
    GopherDaily
    GopherDaily
    Apr 26, 2022
    1
    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
    ch2
    Apr 27, 2022 via iPhone
    2
    CMD 表示的是 docker run 或者 start 运行时执行的命令,在构建的时候放在哪无任何区别
    wd
    wd
    Apr 27, 2022 via iPhone
    3
    你没弄明白 build 和 run 的区别...
    About   ·   Help   ·   Advertise   ·   Blog   ·   API   ·   FAQ   ·   Privacy   ·   Solana   ·   1031 Online   Highest 6679   ·     Select Language
    创意工作者们的社区
    World is powered by solitude
    VERSION: 3.9.8.5 · 49ms · UTC 23:07 · PVG 07:07 · LAX 15:07 · JFK 18:07
    ♥ Do have faith in what you're doing.