Apply Custom Metadata

Source: Internet
Author: User

You can use LABEL meta data to apply to your image, container, or daemon. Metadata can serve a wide range of purposes. Use tags to add comments or license information to a mirror and to flag your host

tags are <key> / <value> key-value pairs, and Docker stores the labels as strings. You can specify multiple labels but each <key> / <value> must be different to prevent overwriting of existing key-value pairs. If you key specify several different values for the same one, the new values will overwrite the previous values. Remember, for the same key , Docker will only apply the last value you provide.

note that the daemon-labels is supported for ocker1.4.1 versions after:D, and label support for labels and containers is a new feature in 1.6.0.

Label Keys (namespaces)

Tag 键 , (aka namespace)

Docker has no hard-pressed restrictions on the keys in the tags you create, but simple keys can also be conflicting. For example, you architecture can categorize your images by tags:

LABELarchitecture="amd64"LABELarchitecture="ARMv7"

Users can also label images with different styles of tags:

LABELarchitecture="Art Nouveau"

To prevent naming collisions, the namespace tag key for Docker uses a 反向域名 representation. Refer to the following to name your key:

    • All (third-party) tools are named after the reverse domain name prefix + tag, which is the same as the domain name provided by the tool author, com.example.some-labelcom.example.some-auther="root"
    • com.docker.*, io.docker.* and com.dockerproject.* reserved for Docker internal use
    • Keys can only be lowercase letters, numbers, dots and - representations, and[a-z0-9-.]
    • The start and end of key names can only be letters and numbers
    • Cannot contain continuous - and point
    • Labels without namespaces are reserved CLI , which allows end users to add Canadian data to containers and mirrors without having to enter cumbersome commands at the terminal

The guidelines are listed above and Docker strictly complies with the implementation. If you do not follow these guidelines it may cause a conflict of label names. If you happen to use the Tag Builder tool, use the namespace for your tags and keys.

Store structured data in labels

Storing structured data in labels

The value in the tag can contain any value that can be stored as a string, such as the following JSON-formatted data:

{    "Description":"A containerized foobar",    "Usage":"Docker run--rm Example/foobar [args]",    "License":"GPL",    "Version":"0.0.1-beta",    "Aboolean":true,    "anumber" :0.01234,    "Anestedarray":["A", "B", "C"]}

To store this structure in a tag, you first need to serialize it to a string:

LABEL com.example.image-specs= "{\"Description\":\"A containerized foobar\",\"Usage\":\"Docker Run--RM Example\\/foobar[Args]\",\"License\":\"Gpl\",\"Version\":\"0.0.1-beta\",\"Aboolean\": true,\"Anumber\": 0.01234,\"Anestedarray\":[\"A\",\"B\",\"C\"]}"

Although structured data can be stored in tags, Docker considers it (structured data) as a normal string. This means that Docker itself does not provide a query (filter) based on nested attributes. If your tool needs to be filtered by nested properties, then your tool itself will implement this function, and don't let Docker do it.

ADD labels to images; The LABEL instruction

LABELtagging images with directives

...

The label directive is used to add a label to the image, optionally setting its value. For 空格 the label you use, use 双引号 or 反斜杠 .
e.g.

com.example.version.iscom.example.version="0.0.1-beta"com.example.release-date="2015-02-12"

Note: There are only keys in the second row above and no value.
The label directive supports LABEL setting multiple
e.g.

com.example.version="0.0.1-beta"com.example.release-date="2015-02-12"

Docker allows \ 1 lines of instruction to be split into multiple rows using backslashes

LABEL vendor=ACME\ Incorporated       com.example.is-beta       com.example.version="0.0.1-beta"       com.example.release-date="2015-02-12"

Docker recommends that you set multiple labels in a label directive , and each tag is set separately with the instructions, which makes your image very much 低效 , because the label instructions in each dockerfile will produce 1 mirrored layers (angry, This explanation is direct to the essence!!!

We can use it docker inspect to view the label of the mirror or container.

Query Labels

Query label

tags, in addition to storing metadata, can also be used to filter images and containers. The following command will list all the com.example.is-beta containers that contain the label and run it:

docker ps --filter"label=com.example.is-beta"

colorLabel and value blue of the in-run container

docker ps --filter"label=color=blue"

vendorimage containing and ACME

docker images --filter"label=vendor=ACME"
Daemon Labels

Guardian Tag

docker infoThe explanation of this command is: Display system-wide information(显示全部信息)
Here are the results on my computer:

Adolph@geek:~$ Docker infoContainers: 7Images:  -Storage Driver:AufsRoot Dir:/var/lib/docker/aufsbacking Filesystem:ExtfsDirs:  - Dirperm1 supported: falseExecution Driver:native-0.2Kernel Version: 3.13.0- the-genericOperating System: Ubuntu 14.04.2 LTSCPUs: 4 Total Memory: 7.687 GiBName:GeekID: HGR7: Ugww: VQVV: WYMF: Csee: kj4c: Qs4u: Iriu: Lreb: M4yc: Gdjy: YPI5Username:AdolphlwqRegistry:[https://index.docker.io/v1/]WARNING: NoSwap limit Support

You can see that it's mostly about Docker daemon, and there's no tag information about it. But we can `docker -d label=value add tags to the Docker daemon itself in a way:

docker -d   --dns 8.8.8.8   --dns 8.8.4.4   -H unix:///var/run/docker.sock   --label com.example.environment="production"   --label com.example.storage="ssd"

Apply Custom Metadata

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.