# Predefined ARGS（预先定义好的ARG变量）

**Docker**有一组预先定义**ARG**变量，我们可以在**Dockerfile**中不声明**ARG**变量的情况下使用这些变量。

* **HTTP\_PROXY**
* **http\_proxy**
* **HTTPS\_PROXY**
* **https\_proxy**
* **FTP\_PROXY**
* **ftp\_proxy**
* **NO\_PROXY**
* **no\_proxy**

为了使用这些变量，我们可以通过命令行标志传递值。

```bash
--build-arg <varname>=<value>
```

默认情况下，这些预先定义的变量被排除在**docker history**的输出之外。排除它们可降低在**HTTP\_PROXY**变量中意外泄露敏感身份验证信息的风险。

思考下面的例子：**Dockerfile**使用&#x4E86;**--build-arg HTTP\_PROXY=**[**http://user:pass@proxy.lon.example.com**](http://user:pass@proxy.lon.example.com)

```
FROM ubuntu
RUN echo "Hello World"
```

在这种情况下，**HTTP\_PROXY**变量的值在**docker history**中不可用，并且未缓存。如果想要更改位置，将代理服务器更改为[http://user:pass@proxy.sfo.example.com，则后续的构建不会导致缓存丢失。](http://user:pass@proxy.sfo.example.xn--com,-jb5fke78ejzk32e24pexfh5bp3rn84ay90che2awsar82b)

如果需要覆盖此行为，则可以在**Dockerfile**中添加**ARG**声明，如下所示：

```
FROM ubuntu
ARG HTTP_PROXY
RUN echo "Hello World"
```

当构建这个**Dockerfile**时，**HTTP\_PROXY**会保留在**docker history**中，修改该变量的值会导致缓存失效。


---

# 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/predefined-args-yu-xian-ding-yi-hao-de-arg-bian-liang.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.
