分享
三行代码  ›  专栏  ›  技术社区  ›  Elie G.

Docker ARG变量不工作(始终为空)

  •  0
  • Elie G.  · 技术社区  · 1 周前

    为什么dockerfile中的ARG变量总是空的?

    命令

    docker build --rm --force-rm --no-cache -f ./Dockerfile
    

    Dockerfile文件

    ARG APP_NAME='ground-station'
    
    FROM node:current AS build-node
    WORKDIR /${APP_NAME}
    RUN echo "APP_NAME=${APP_NAME}"
    

    输出

    Sending build context to Docker daemon  1.199MB
    Step 1/4 : ARG APP_NAME='ground-station'
    Step 2/4 : FROM node:current AS build-node
     ---> 6e72986b1b6e
    Step 3/4 : WORKDIR /${APP_NAME}
     ---> Running in 39f12e36d4a1
    Removing intermediate container 39f12e36d4a1
     ---> 93f5cdef6402
    Step 4/4 : RUN echo "APP_NAME=${APP_NAME}"
     ---> Running in a18ac6f3bee8
    APP_NAME=
    Removing intermediate container a18ac6f3bee8
     ---> 746cea84bb8f
    Successfully built 746cea84bb8f
    

    APP_NAME 总是空的。

    this . 我试过了 --no-cache


    docker version

    Client: Docker Engine - Community
     Version:           20.10.5
     API version:       1.41
     Go version:        go1.13.15
     Git commit:        55c4c88
     Built:             Tue Mar  2 20:17:52 2021
     OS/Arch:           linux/amd64
     Context:           default
     Experimental:      true
    
    Server: Docker Engine - Community
     Engine:
      Version:          20.10.5
      API version:      1.41 (minimum version 1.12)
      Go version:       go1.13.15
      Git commit:       363e9a8
      Built:            Tue Mar  2 20:15:47 2021
      OS/Arch:          linux/amd64
      Experimental:     false
     containerd:
      Version:          1.4.4
      GitCommit:        05f951a3781f4f2c1911b05e61c160e9c30eaa8e
     runc:
      Version:          1.0.0-rc93
      GitCommit:        12644e614e25b05da6fd08a38ffa0cfe1903fdec
     docker-init:
      Version:          0.19.0
      GitCommit:        de40ad0
    
    1 回复  |  直到 1 周前
        1
  •  0
  •   BMitch    1 周前

    ARG steps are scoped . 在第一个之前 FROM 精氨酸 仅适用于 精氨酸 一步一步走到下一步 (在多级构建中)。

    FROM node:current AS build-node
    ARG APP_NAME='ground-station'
    WORKDIR /${APP_NAME}
    RUN echo "APP_NAME=${APP_NAME}"