【Docker】Dockerfile 之 LABEL


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

環境

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

LABEL

LABEL <key>=<value> <key>=<value> <key>=<value> ...

The LABEL instruction adds metadata to an image. A LABEL is a key-value pair. To include spaces within a LABEL value, use quotes and backslashes as you would in command-line parsing. A few usage examples:

LABEL 指令將元數據添加到鏡像。LABEL 是鍵值對。要在 LABEL 值中包含空格,請像在命令行中一樣使用引號和反斜杠。一些用法示例:

LABEL "com.example.vendor"="ACME Incorporated"
LABEL com.example.label-with-value="foo"
LABEL version="1.0"
LABEL description="This text illustrates \
that label-values can span multiple lines."

An image can have more than one label. You can specify multiple labels on a single line. Prior to Docker 1.10, this decreased the size of the final image, but this is no longer the case. You may still choose to specify multiple labels in a single instruction, in one of the following two ways:

一個鏡像可以有多個標簽。您可以在一行上指定多個標簽。在 Docker 1.10 之前,這減小了最終鏡像的大小,但是現在不再如此。您仍然可以選擇以下兩種方式之一在一條指令中指定多個標簽:

LABEL multi.label1="value1" multi.label2="value2" other="value3"
LABEL multi.label1="value1" \
      multi.label2="value2" \
      other="value3"

Labels included in base or parent images (images in the FROM line) are inherited by your image. If a label already exists but with a different value, the most-recently-applied value overrides any previously-set value.

基礎或父鏡像(FROM 行中的鏡像)中包含的標簽由您的鏡像繼承。如果標簽已經存在但具有不同的值,則最近應用的值將覆蓋任何先前設置的值。

To view an image’s labels, use the docker image inspect command. You can use the --format option to show just the labels;

要查看鏡像的標簽,請使用 docker image inspect 命令。您可以使用 --format 選項僅顯示標簽;

docker image inspect --format='' myimage
{
  "com.example.vendor": "ACME Incorporated",
  "com.example.label-with-value": "foo",
  "version": "1.0",
  "description": "This text illustrates that label-values can span multiple lines.",
  "multi.label1": "value1",
  "multi.label2": "value2",
  "other": "value3"
}

示例

Dockerfile 文件

FROM busybox
LABEL author=jiangbo
CMD echo jiangbo

構建結果

[root@master env]# docker build -t jiangbo:0.0.1 . --no-cache
Sending build context to Docker daemon  3.584kB
Step 1/3 : FROM busybox
 ---> dc3bacd8b5ea
Step 2/3 : LABEL author=jiangbo
 ---> Running in 0ff7462c023b
Removing intermediate container 0ff7462c023b
 ---> bae66ec32f55
Step 3/3 : CMD echo jiangbo
 ---> Running in 2a3701bc64fc
Removing intermediate container 2a3701bc64fc
 ---> f75b03f5ec1f
Successfully built f75b03f5ec1f
Successfully tagged jiangbo:0.0.1
[root@master env]#

查看標簽

[root@master env]# docker image inspect jiangbo:0.0.1 --format "{{json .ContainerConfig.Labels}}"|jq
{
  "author": "jiangbo"
}

MAINTAINER

MAINTAINER 已過時,使用 LABEL 代替。

總結

介紹了 Dockerfile 中 LABEL 指令的使用。


免責聲明!

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



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