Dockerfile中的ARG指令详解

来源:互联网 发布:2017年网络热词 编辑:程序博客网 时间:2024/06/05 20:58

Dockerfile中的ARG指令用以定义构建时需要的参数,使用格式如下:

ARG a_nameARG a_nother_name=a_default_value

ARG指令定义的参数,在docker build命令中以--build-arg a_name=a_value形式赋值。

如果docker build命令传递的参数,在Dockerfile中没有对应的参数,将抛出如下警告:

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

如果在Dockerfile中,ARG指令定义参数之前,就有其他指令引用了参数,则参数值为空字符串。
不建议在构建的过程中,以参数的形式传递保密信息,如key, password等。


Docker自带的如下ARG参数,可以在其他指令中直接引用:

  • HTTP_PROXY
  • http_proxy
  • HTTPS_PROXY
  • https_proxy
  • FTP_PROXY
  • ftp_proxy
  • NO_PROXY
  • no_proxy

参考链接:

https://docs.docker.com/engine/reference/builder/