> For the complete documentation index, see [llms.txt](https://camelgemonion.gitbook.io/docker/llms.txt). Markdown versions of documentation pages are available by appending `.md` to page URLs; this page is available as [Markdown](https://camelgemonion.gitbook.io/docker/dockerfile-zhi-ling/parser-directives.md).

# Parser directives

## Parser directives

**解析器指令**是可选的，并且会影响**Dockerfile**中后续行的处理方式。**解析器指令**不会在构建中添加镜像层，也不会在构建步骤中显示。**解析器指令以＃指令=值的形式写为特殊的注释类型。**&#x5355;个指令只能使用一次。

**处理完注释，空行或构建器指令后，Docker不再寻找解析器指令，而是将格式化为解析器指令的任何内容都视为注释，并且不会尝试验证它是否可能是解析器指令。因此，所有解析器指令必须位于Dockerfile的最顶部。**

**解析器指令**不区分大小写。但是根据约定是小写的。约定还包括应在任何**解析器指令**之后包含一个空白行。**解析器指令**不支持行继续符。

由于这些规则，以下示例均无效：

由于行继续符而无效：

```
# direc \
tive=value
```

下面的指令无效的，因为出现了两次

```
# directive=value1
# directive=value2

FROM ImageName
```

会被当成注释，因为解析器指令出现在了构建器指令后面

```
FROM ImageName
# directive=value
```

会被当成注释，因为解析器指令出现在了注释后面

```
# About my dockerfile
# directive=value
FROM ImageName
```

由于无法被识别，未知指令被视为注释。另外，由于在不是**解析器指令**的注释之后出现，所以已知指令被视为注释。

```
# unknowndirective=value  #无法被识别，因此当成注释
# knowndirective=valuev  #由于前面的指令备当成了注释，出现在注释后面的解析器指令被当成注释对待。
```

**解析器指令**中允许使用不换行的空格。因此，以下各行都被相同地对待：

```
#directive=value
# directive =value
#    directive= value
# directive = value
#      dIrEcTiVe=value
```

以下两个指令是支持的**解析器指令**:

* **syntax**
* **escape**


---

# Agent Instructions
This documentation is published with GitBook. GitBook is the documentation platform designed so that both humans and AI agents can read, navigate, and reason over technical content effectively. Learn more at gitbook.com.

## 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/parser-directives.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.
