1. 程式人生 > 實用技巧 >【Docker】Dockerfile 解析器指令

【Docker】Dockerfile 解析器指令

參考教程:https://docs.docker.com/engine/reference/builder/

環境

  1. virtual box 6.1
  2. centos 7.8
  3. docker 19.03

解析器指令

Parser directives are optional, and affect the way in which subsequent lines in a Dockerfile are handled. Parser directives do not add layers to the build, and will not be shown as a build step. Parser directives are written as a special type of comment in the form # directive=value

. A single directive may only be used once.

解析器指令是可選的,並且會影響 Dockerfile 中後續行的處理方式。解析器指令不會在構建中新增映象層,也不會顯示為構建步驟。解析器指令以 # directive=value 的形式寫為特殊的註釋型別。單個指令只能使用一次。

Once a comment, empty line or builder instruction has been processed, Docker no longer looks for parser directives. Instead it treats anything formatted as a parser directive as a comment and does not attempt to validate if it might be a parser directive. Therefore, all parser directives must be at the very top of a Dockerfile

.

處理完註釋,空行或生成器指令後,Docker 不再尋找解析器指令。而是將格式化為解析器指令的任何內容都視為註釋,並且不會嘗試驗證它是否可能是解析器指令。因此,所有解析器指令必須位於 Dockerfile 的最頂部。

Parser directives are not case-sensitive. However, convention is for them to be lowercase. Convention is also to include a blank line following any parser directives. Line continuation characters are not supported in parser directives.

解析器指令不區分大小寫。但是,約定是小寫的。約定還應在任何解析器指令之後包含一個空白行。解析器偽指令不支援行繼續符。

Due to these rules, the following examples are all invalid:

由於這些規則,以下示例均無效:

Invalid due to line continuation:

由於行繼續而無效:

# direc \
tive=value

Invalid due to appearing twice:

由於出現兩次而無效:

# directive=value1
# directive=value2

FROM ImageName

Treated as a comment due to appearing after a builder instruction:

由於在構建指令之後出現,因此被視為註釋:

FROM ImageName
# directive=value

Treated as a comment due to appearing after a comment which is not a parser directive:

由於出現在不是解析器指令的註釋之後,因此被視為註釋:

# About my dockerfile
# directive=value
FROM ImageName

The unknown directive is treated as a comment due to not being recognized. In addition, the known directive is treated as a comment due to appearing after a comment which is not a parser directive.

由於未被識別,未知指令被視為註釋。另外,由於在非解析程式指令的註釋之後出現,因此已知指令被視為註釋。

# unknowndirective=value
# knowndirective=value

Non line-breaking whitespace is permitted in a parser directive. Hence, the following lines are all treated identically:

解析器指令中允許非換行空格。因此,以下各行都被相同地對待:

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

The following parser directives are supported:

支援以下解析器指令:

  • syntax
  • escape

總結

介紹了 Dockerfile 的解析器指令格式。