args
添加只有在构建阶段才能访问的环境变量。
首先在Dockerfile中指定这些参数:
ARG buildno
ARG gitcommithash
RUN echo "Build number: $buildno"
RUN echo "Based on commit: $gitcommithash"
然后在Compose文件中的build字段下面指定这些参数的值:
build:
context: .
args:
buildno: 1
gitcommithash: cdc3b19
build:
context: .
args:
- buildno=1
- gitcommithash=cdc3b19
在指定构建参数时,可以省略该值。如果省略了值,则这些变量的值会从Compose运行的环境中去获取。
args:
- buildno
- gitcommithash
Note:
使用boolean值时,用双引号包围这些值,以便可以被解析为字符串。
Last updated
Was this helpful?