【Docker】Dockerfile 最佳實踐-LABEL


參考教程:https://docs.docker.com/develop/develop-images/dockerfile_best-practices/

環境

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

LABEL

You can add labels to your image to help organize images by project, record licensing information, to aid in automation, or for other reasons. For each label, add a line beginning with LABEL and with one or more key-value pairs. The following examples show the different acceptable formats. Explanatory comments are included inline.

您可以在鏡像上添加標簽,以幫助按項目組織鏡像,記錄許可信息,幫助自動化或其他原因。對於每個標簽,添加以 LABEL 開頭並帶有一個或多個鍵值對的行。以下示例顯示了不同的可接受格式。內嵌包含解釋性注釋。

Strings with spaces must be quoted or the spaces must be escaped. Inner quote characters ("), must also be escaped.

帶有空格的字符串必須用引號引起來,或者必須將空格轉義。內引號字符(“"”)也必須轉義。

# Set one or more individual labels
LABEL com.example.version="0.0.1-beta"
LABEL vendor1="ACME Incorporated"
LABEL vendor2=ZENITH\ Incorporated
LABEL com.example.release-date="2015-02-12"
LABEL com.example.version.is-production=""

An image can have more than one label. Prior to Docker 1.10, it was recommended to combine all labels into a single LABEL instruction, to prevent extra layers from being created. This is no longer necessary, but combining labels is still supported.

一個鏡像可以有多個標簽。在 Docker 1.10 之前,建議將所有標簽合並為一個 LABEL 指令,以防止創建額外的層。現在不再需要此操作,但仍支持組合標簽。

# Set multiple labels on one line
LABEL com.example.version="0.0.1-beta" com.example.release-date="2015-02-12"

The above can also be written as:
上面也可以寫成:

# Set multiple labels at once, using line-continuation characters to break long lines
LABEL vendor=ACME\ Incorporated \
      com.example.is-beta= \
      com.example.is-production="" \
      com.example.version="0.0.1-beta" \
      com.example.release-date="2015-02-12"

See Understanding object labels for guidelines about acceptable label keys and values. For information about querying labels, refer to the items related to filtering in Managing labels on objects. See also LABEL in the Dockerfile reference.

請參閱了解對象標簽了解有關可接受的標簽鍵和值的准則。有關查詢標簽的信息,請參閱管理對象上的標簽中與過濾有關的項目。另請參閱 Dockerfile 參考中的 LABEL

總結

介紹了 Dockerfile 的 LABEL 指令的最佳實踐。


免責聲明!

本站轉載的文章為個人學習借鑒使用,本站對版權不負任何法律責任。如果侵犯了您的隱私權益,請聯系本站郵箱yoyou2525@163.com刪除。



 
粵ICP備18138465號   © 2018-2025 CODEPRJ.COM