V2EX = way to explore
V2EX 是一个关于分享和探索的地方
Sign Up Now
For Existing Member  Sign In
vonsy
V2EX  ›  Docker

请教一个 docker 打包的问题

  •  
  •   vonsy · Apr 26, 2022 · 1927 views
    This topic created in 1467 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
        1
    GopherDaily  
       Apr 26, 2022
    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  
       Apr 27, 2022 via iPhone
    CMD 表示的是 docker run 或者 start 运行时执行的命令,在构建的时候放在哪无任何区别
    wd
        3
    wd  
       Apr 27, 2022 via iPhone
    你没弄明白 build 和 run 的区别...
    About   ·   Help   ·   Advertise   ·   Blog   ·   API   ·   FAQ   ·   Solana   ·   2475 Online   Highest 6679   ·     Select Language
    创意工作者们的社区
    World is powered by solitude
    VERSION: 3.9.8.5 · 42ms · UTC 08:42 · PVG 16:42 · LAX 01:42 · JFK 04:42
    ♥ Do have faith in what you're doing.