Revise documentation for Docker LABEL.
| ... | ... |
@@ -11,34 +11,35 @@ parent = "mn_use_docker" |
| 11 | 11 |
# Apply custom metadata |
| 12 | 12 |
|
| 13 | 13 |
You can apply metadata to your images, containers, or daemons via |
| 14 |
-labels. Metadata can serve a wide range of uses. Use labels to add notes or |
|
| 15 |
-licensing information to an image or to identify a host. |
|
| 14 |
+labels. Labels serve a wide range of uses, such as adding notes or licensing |
|
| 15 |
+information to an image, or to identify a host. |
|
| 16 | 16 |
|
| 17 | 17 |
A label is a `<key>` / `<value>` pair. Docker stores the label values as |
| 18 |
-*strings*. You can specify multiple labels but each `<key>` / `<value>` must be |
|
| 19 |
-unique to avoid overwriting. If you specify the same `key` several times but with |
|
| 20 |
-different values, newer labels overwrite previous labels. Docker uses |
|
| 21 |
-the last `key=value` you supply. |
|
| 18 |
+*strings*. You can specify multiple labels but each `<key>` must be |
|
| 19 |
+unique or the value will be overwritten. If you specify the same `key` several |
|
| 20 |
+times but with different values, newer labels overwrite previous labels. Docker |
|
| 21 |
+uses the last `key=value` you supply. |
|
| 22 | 22 |
|
| 23 | 23 |
>**Note:** Support for daemon-labels was added in Docker 1.4.1. Labels on |
| 24 | 24 |
>containers and images are new in Docker 1.6.0 |
| 25 | 25 |
|
| 26 | 26 |
## Label keys (namespaces) |
| 27 | 27 |
|
| 28 |
-Docker puts no hard restrictions on the label `key` you. However, labels with |
|
| 29 |
-simple keys can conflict. For example, you can categorize your images by using a |
|
| 30 |
-chip "architecture" label: |
|
| 28 |
+Docker puts no hard restrictions on the `key` used for a label. However, using |
|
| 29 |
+simple keys can easily lead to conflicts. For example, you have chosen to |
|
| 30 |
+categorize your images by CPU architecture using "architecture" labels in |
|
| 31 |
+your Dockerfiles: |
|
| 31 | 32 |
|
| 32 | 33 |
LABEL architecture="amd64" |
| 33 | 34 |
|
| 34 | 35 |
LABEL architecture="ARMv7" |
| 35 | 36 |
|
| 36 |
-But a user can label images by building architectural style: |
|
| 37 |
+Another user may apply the same label based on a building's "architecture": |
|
| 37 | 38 |
|
| 38 | 39 |
LABEL architecture="Art Nouveau" |
| 39 | 40 |
|
| 40 |
-To prevent naming conflicts, Docker namespaces label keys using a reverse domain |
|
| 41 |
-notation. Use the following guidelines to name your keys: |
|
| 41 |
+To prevent naming conflicts, Docker recommends using namespaces to label keys |
|
| 42 |
+using reverse domain notation. Use the following guidelines to name your keys: |
|
| 42 | 43 |
|
| 43 | 44 |
- All (third-party) tools should prefix their keys with the |
| 44 | 45 |
reverse DNS notation of a domain controlled by the author. For |
| ... | ... |
@@ -59,15 +60,14 @@ notation. Use the following guidelines to name your keys: |
| 59 | 59 |
cumbersome namespaces on the command-line. |
| 60 | 60 |
|
| 61 | 61 |
|
| 62 |
-These are guidelines and Docker does not *enforce* them. Failing following these |
|
| 63 |
-guidelines can result in conflicting labels. If you're building a tool that uses |
|
| 64 |
-labels, you *should* use namespaces for your label keys. |
|
| 62 |
+These are simply guidelines and Docker does not *enforce* them. However, for |
|
| 63 |
+the benefit of the community, you *should* use namespaces for your label keys. |
|
| 65 | 64 |
|
| 66 | 65 |
|
| 67 | 66 |
## Store structured data in labels |
| 68 | 67 |
|
| 69 |
-Label values can contain any data type that can be stored as a string. For |
|
| 70 |
-example, consider this JSON: |
|
| 68 |
+Label values can contain any data type as long as it can be represented as a |
|
| 69 |
+string. For example, consider this JSON document: |
|
| 71 | 70 |
|
| 72 | 71 |
|
| 73 | 72 |
{
|
| ... | ... |
@@ -87,31 +87,31 @@ You can store this struct in a label by serializing it to a string first: |
| 87 | 87 |
While it is *possible* to store structured data in label values, Docker treats |
| 88 | 88 |
this data as a 'regular' string. This means that Docker doesn't offer ways to |
| 89 | 89 |
query (filter) based on nested properties. If your tool needs to filter on |
| 90 |
-nested properties, the tool itself should implement this. |
|
| 90 |
+nested properties, the tool itself needs to implement this functionality. |
|
| 91 | 91 |
|
| 92 | 92 |
|
| 93 |
-## Add labels to images; the `LABEL` instruction |
|
| 93 |
+## Add labels to images |
|
| 94 | 94 |
|
| 95 |
-Adding labels to an image: |
|
| 95 |
+To add labels to an image, use the `LABEL` instruction in your Dockerfile: |
|
| 96 | 96 |
|
| 97 | 97 |
|
| 98 | 98 |
LABEL [<namespace>.]<key>[=<value>] ... |
| 99 | 99 |
|
| 100 |
-The `LABEL` instruction adds a label to your image, optionally setting its value. |
|
| 100 |
+The `LABEL` instruction adds a label to your image, optionally with a value. |
|
| 101 | 101 |
Use surrounding quotes or backslashes for labels that contain |
| 102 |
-white space character: |
|
| 102 |
+white space characters in the `<value>`: |
|
| 103 | 103 |
|
| 104 | 104 |
LABEL vendor=ACME\ Incorporated |
| 105 | 105 |
LABEL com.example.version.is-beta |
| 106 | 106 |
LABEL com.example.version="0.0.1-beta" |
| 107 | 107 |
LABEL com.example.release-date="2015-02-12" |
| 108 | 108 |
|
| 109 |
-The `LABEL` instruction supports setting multiple labels in a single instruction |
|
| 110 |
-using this notation: |
|
| 109 |
+The `LABEL` instruction also supports setting multiple `<key>` / `<value>` pairs |
|
| 110 |
+in a single instruction: |
|
| 111 | 111 |
|
| 112 | 112 |
LABEL com.example.version="0.0.1-beta" com.example.release-date="2015-02-12" |
| 113 | 113 |
|
| 114 |
-Wrapping is allowed by using a backslash (`\`) as continuation marker: |
|
| 114 |
+Long lines can be split up by using a backslash (`\`) as continuation marker: |
|
| 115 | 115 |
|
| 116 | 116 |
LABEL vendor=ACME\ Incorporated \ |
| 117 | 117 |
com.example.is-beta \ |
| ... | ... |
@@ -120,7 +120,7 @@ Wrapping is allowed by using a backslash (`\`) as continuation marker: |
| 120 | 120 |
|
| 121 | 121 |
Docker recommends you add multiple labels in a single `LABEL` instruction. Using |
| 122 | 122 |
individual instructions for each label can result in an inefficient image. This |
| 123 |
-is because each `LABEL` instruction in a Dockerfile produces a new IMAGE layer. |
|
| 123 |
+is because each `LABEL` instruction in a Dockerfile produces a new IMAGE layer. |
|
| 124 | 124 |
|
| 125 | 125 |
You can view the labels via the `docker inspect` command: |
| 126 | 126 |
|
| ... | ... |
@@ -147,16 +147,16 @@ You can view the labels via the `docker inspect` command: |
| 147 | 147 |
## Query labels |
| 148 | 148 |
|
| 149 | 149 |
Besides storing metadata, you can filter images and containers by label. To list all |
| 150 |
-running containers that the `com.example.is-beta` label: |
|
| 150 |
+running containers that have the `com.example.is-beta` label: |
|
| 151 | 151 |
|
| 152 | 152 |
# List all running containers that have a `com.example.is-beta` label |
| 153 | 153 |
$ docker ps --filter "label=com.example.is-beta" |
| 154 | 154 |
|
| 155 |
-List all running containers with a `color` label of `blue`: |
|
| 155 |
+List all running containers with the label `color` that have a value `blue`: |
|
| 156 | 156 |
|
| 157 | 157 |
$ docker ps --filter "label=color=blue" |
| 158 | 158 |
|
| 159 |
-List all images with `vendor` `ACME`: |
|
| 159 |
+List all images with the label `vendor` that have the value `ACME`: |
|
| 160 | 160 |
|
| 161 | 161 |
$ docker images --filter "label=vendor=ACME" |
| 162 | 162 |
|