# ARG

```
ARG <name>[=<default value>]
```

**ARG指令**定义了一个用户能够在构建时通过**docker build --build-arg \<key>=\<value>**&#x4F20;递给构建器的变量。如果用户指定了一个没有在**Dockerfile**中定义的构建参数，构建将输出一个警告。

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

**Dockerfile**可以包含多个**ARG指令**，例如下面就是一个有效的**Dockerfile**：

```
FROM busybox
ARG user1
ARG buildno
# ...
```

**Warning：**

不推荐使用构建时（**build-time**）变量传递私密信息（**secrets**）**,** 如**github**密钥、用户凭据等。任何一个镜像的用户使用**docker history**命令都可以查看到镜像的构建时（**build-time**）变量值。

参考使用[**BuildKit构建镜像**](https://docs.docker.com/develop/develop-images/build_enhancements/#new-docker-build-secret-information)的部分，了解在构建镜像时使用**secrets**的安全方法 。


---

# Agent Instructions: Querying This Documentation

If you need additional information that is not directly available in this page, you can query the documentation dynamically by asking a question.

Perform an HTTP GET request on the current page URL with the `ask` query parameter:

```
GET https://camelgemonion.gitbook.io/docker/dockerfile-zhi-ling/arg.md?ask=<question>
```

The question should be specific, self-contained, and written in natural language.
The response will contain a direct answer to the question and relevant excerpts and sources from the documentation.

Use this mechanism when the answer is not explicitly present in the current page, you need clarification or additional context, or you want to retrieve related documentation sections.
