参考教程:https://docs.docker.com/engine/reference/builder/

环境

  1. virtual box 6.1
  2. centos 7.8
  3. docker 19.03

ARG

ARG <name>[=<default value>]

The ARG instruction defines a variable that users can pass at build-time to the builder with the docker build command using the --build-arg <varname>=<value> flag. If a user specifies a build argument that was not defined in the Dockerfile, the build outputs a warning.

ARG 指令定义了一个变量,用户可以在构建时使用 docker build 命令使用--build-arg <varname>=<value> 标志将其传递给构建器。如果用户指定了未在 Dockerfile 中定义的构建参数,则构建会输出警告。

[Warning] One or more build-args [foo] were not consumed.

A Dockerfile may include one or more ARG instructions. For example, the following is a valid Dockerfile:

Dockerfile 可能包含一个或多个 ARG 指令。例如,以下是有效的 Dockerfile:

FROM busybox
ARG user1
ARG buildno
# ...

Warning:

It is not recommended to use build-time variables for passing secrets like github keys, user credentials etc. Build-time variable values are visible to any user of the image with the docker history command.

警告:

不建议使用构建时变量来传递诸如 github 密钥,用户凭据等机密。构建时变量值对于使用 docker history 命令的镜像的任何用户都是可见的。

默认值

An ARG instruction can optionally include a default value:

ARG 指令可以选择包含默认值:

FROM busybox
ARG user1=someuser
ARG buildno=1
# ...

If an ARG instruction has a default value and if there is no value passed at build-time, the builder uses the default.

如果 ARG 指令具有默认值,并且在构建时未传递任何值,则构建器将使用默认值。

范围

An ARG variable definition comes into effect from the line on which it is defined in the Dockerfile not from the argument’s use on the command-line or elsewhere. For example, consider this Dockerfile:

ARG 变量从 Dockerfile 中定义的行开始生效,而不是从命令行或其他地方的自变量使用开始。例如,考虑以下 Dockerfile:

FROM busybox
USER ${user:-some_user}
ARG user
USER $user
# ...

A user builds this file by calling:

$ docker build --build-arg user=what_user .

The USER at line 2 evaluates to some_user as the user variable is defined on the subsequent line 3. The USER at line 4 evaluates to what_user as user is defined and the what_user value was passed on the command line. Prior to its definition by an ARG instruction, any use of a variable results in an empty string.

第 2 行的 USER 评估为 some_user,因为在随后的第 3 行中定义了 USER 变量。第 4 行的 USER 评估为 what_user,因为定义了 user,并且为 what_user 在命令行中传递。在通过 ARG 指令对其进行定义之前,对变量的任何使用都会导致一个空字符串。

An ARG instruction goes out of scope at the end of the build stage where it was defined. To use an arg in multiple stages, each stage must include the ARG instruction.

ARG 指令在定义它的构建阶段结束时超出范围。要在多个阶段使用变量,每个阶段都必须包含 ARG 指令。

FROM busybox
ARG SETTINGS
RUN ./run/setup $SETTINGSFROM busybox
ARG SETTINGS
RUN ./run/other $SETTINGS

总结

介绍了 Dockerfile 中 ARG 指令的说明,默认值和范围。

Dockerfile 之 ARG指令详解及示例相关推荐

  1. Dockerfile配置指令详解

    Dockerfile配置指令详解 一.FROM 二.RUN 三.CMD 四.EXPOSE 五.ENV 六.ADD 七.COPY 八.ENTRYPOINT 九.VOLUME 十.USER 十一.WORK ...

  2. Dockerfile 指令详解1

    Dockerfile 指令详解 我们已经介绍了 FROM,RUN,还提及了 COPY, ADD,其实 Dockerfile 功能很强大,它提供了十多个指令.下面我们继续讲解其他的指令. COPY 复制 ...

  3. c语言将两个16位变为一个32位,16位汇编第六讲汇编指令详解第第三讲(示例代码)...

    16位汇编第六讲汇编指令详解第第三讲 1.十进制调整指令 1. 十进制数调整指令对二进制运算的结果进行十进制调整,以得到十进制的运算结果 2.分成压缩BCD码和非压缩BCD码调整 简而言之: 以前的时 ...

  4. Docker技术入门与实战 第二版-学习笔记-3-Dockerfile 指令详解

    前面已经讲解了FROM.RUN指令,还提及了COPY.ADD,接下来学习其他的指令 5.Dockerfile 指令详解 1> COPY 复制文件 格式: COPY  <源路径> .. ...

  5. Linux中的ps指令详解

    [时间]2018.12.16 [题目]Linux中的ps指令详解 转载地址:https://www.cnblogs.com/exe19/p/5511733.html 概述 要对进程进行监测和控制,首先 ...

  6. Angular ng-model指令详解

    Angular ng-model指令详解 声明 将输入域的值与 AngularJS 创建的变量绑定 双向数据绑定 表单验证 自定义类样式 常用应用状态 声明 本文根据菜鸟教程整理 http://www ...

  7. 搜索引擎高级搜索指令详解

    在当今外贸竞争越来越惨烈的情况下,广大站长没有两把刷子是不行滴.学习外贸SEO就是一个方法. 当初凭借傻瓜式就可以赚取美金等外币的时代已经悄悄远去,当下如果要提高站点排名,提升外贸网站流量,那么必须使 ...

  8. arm-linux-ld中的参数,arm-linux-ld指令详解

    arm-linux-ld指令详解 我们对每个c或者汇编文件进行单独编译,但是不去连接,生成很多.o 的文件,这些.o文件首先是分散的,我们首先要考虑的如何组合起来:其次,这些.o文件存在相互调用的关系 ...

  9. 百度PaddleOCR及云平台OCR API详解及示例

    百度PaddleOCR及云平台OCR API详解及示例 目录 百度PaddleOCR及云平台OCR API详解及示例 使用百度开源的PaddleOCR 多个开源代码库比较

最新文章

  1. virtual hust 2013.6.20 数论基础题目 D - Just the Facts
  2. html制作nba网页,NBA篮球_实用电脑小技巧:通俗解答html 自己动手建一个非常简单的网页_沪江英语...
  3. CVE-2019-8660 iMessage 漏洞复现
  4. 信息系统项目管理师论文优秀范文_软考 信息系统项目管理师备考指南
  5. SQL Serever学习4
  6. 【实习招聘】创新工场首席科学家、原ACL主席、MSRA副院长周明老师领导的NLP团队招聘机器翻译方向实习生...
  7. oracle11g服务配置,oracle11g dg broker配置服务的高可用
  8. AQS-sync同步队列 [自定义同步器框架]
  9. 闭环系统辨识matlab,系统辨识-12-闭环辨识
  10. linux 64 iso镜像文件下载地址,Linux(RHEL) ISO镜像文件-下载地址
  11. Jmeter二次开发实现rsa加密
  12. 用优盘装系统看不到计算机本身的硬盘,电脑u盘重装系统找不到硬盘的3大解决方法...
  13. 基于浏览器内核的被动式爬虫任务下发框架
  14. Notebook for Integer Programming (Laurence A. Wolsey) - Well-Solved Problems
  15. Studing Day1 - python基础1
  16. 显卡报价,一夜闪崩 35%
  17. 为什么阿里巴巴禁止开发人员 boolean 类型变量使用 isXXX 来命名?
  18. vuetify,nginx与cors的使用
  19. 近似计算:π/4=1-1/3+1/5-1/7...
  20. 2017.7.10 noi2008 假面舞会

热门文章

  1. 趣学python3(2)-添加以数字文字形式使用下划线的功能,以提高可读性
  2. 【小白学习PyTorch教程】六、基于CIFAR-10 数据集,使用PyTorch 从头开始​​构建图像分类模型...
  3. 终于有人把文本分类讲明白了!
  4. 【深度总结】聊聊为什么技术要先广后精,对技术新人的几点建议
  5. AAAI-2020 || 52篇深度强化学习accept论文汇总
  6. 大规模推荐Deep Retrieval
  7. 网易加速5G下视频技术应用,携手南京银行数字化转型
  8. 0213互联网新闻 | IBM宣布推出新的混合云产品;Instagram正在内测网页版聊天服务...
  9. Unity检视面板的继承方法研究
  10. 机器视觉与深度神经网络—洗去浮华,一窥珠玑