# 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值时，用双引号包围这些值，以便可以被解析为字符串。


---

# 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/dockercompose.yaml-wen-jian-zhong-chang-yong-zhi-ling/untitled-12/build/args.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.
