Dockerfile LABLE指令

给镜像添加元数据信息

LABEL

可以为生成的镜像添加元数据标签信息,这些信息可以用来辅助过滤出特定镜像

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

栗子一

1
2
3
4
5
6
7
8
9
10
# key 加了 "
LABEL "com.example.vendor"="ACME Incorporated"

# key 没有 "
LABEL com.example.label-with-value="foo"
LABEL version="1.0"

# 换行
LABEL description="This text illustrates \
that label-values can span multiple lines."

栗子二

一行添加多个 key=value

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

等价写法

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

通过 docker inspect 查看添加的元数据

1
2
3
4
5
6
7
8
9
10
> 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"
}