Browse code

Documentation changes for labels

Signed-off-by: Darren Shepherd <darren@rancher.com>

Darren Shepherd authored on 2015/03/17 05:28:55
Showing 10 changed files
... ...
@@ -144,16 +144,19 @@ A Dockerfile is similar to a Makefile.
144 144
   the image.
145 145
 
146 146
 **LABEL**
147
- --**LABEL <key>[=<value>] [<key>[=<value>] ...]**
147
+  -- `LABEL <key>[=<value>] [<key>[=<value>] ...]`
148
+  The **LABEL** instruction adds metadata to an image. A **LABEL** is a
149
+  key-value pair. To include spaces within a **LABEL** value, use quotes and
150
+  blackslashes as you would in command-line parsing.
148 151
 
149
- The **LABEL** instruction allows you to add meta-data to the image your 
150
- Dockerfile is building. LABEL is specified as name value pairs. This data can
151
- be retrieved using the `docker inspect` command.
152
+  ```
153
+  LABEL "com.example.vendor"="ACME Incorporated"
154
+  ```
152 155
 
153
- The LABEL instruction allows for multiple labels to be set at one time. Like 
154
- command line parsing, quotes and backslashes can be used to include spaces 
155
- within values.
156
+  An image can have more than one label. To specify multiple labels, separate each
157
+  key-value pair by a space.
156 158
 
159
+  To display an image's labels, use the `docker inspect` command.
157 160
 
158 161
 **EXPOSE**
159 162
   -- `EXPOSE <port> [<port>...]`
... ...
@@ -105,10 +105,10 @@ IMAGE [COMMAND] [ARG...]
105 105
                                'host': use the host shared memory,semaphores and message queues inside the container.  Note: the host mode gives the container full access to local shared memory and is therefore considered insecure.
106 106
 
107 107
 **-l**, **--label**=[]
108
-   Set meta data on the container (e.g., --label=com.example.key=value)
108
+   Set metadata on the container (e.g., --label=com.example.key=value)
109 109
 
110 110
 **--label-file**=[]
111
-   Read in a line delimited file of labels
111
+   Read in a file of labels (EOL delimited)
112 112
 
113 113
 **--link**=[]
114 114
    Add link to another container in the form of <name or id>:alias
... ...
@@ -34,9 +34,7 @@ versions.
34 34
    Show all images (by default filter out the intermediate image layers). The default is *false*.
35 35
 
36 36
 **-f**, **--filter**=[]
37
-   Provide filter values. Valid filters:
38
-                          dangling=true - unlabeled images with no children
39
-                          label=<key> or label=<key>=<value>
37
+   Filters the output. The dangling=true filter finds unused images. While label=com.foo=amd64 filters for images with a com.foo value of amd64. The label=com.foo filter finds images with the label com.foo of any value.
40 38
 
41 39
 **--help**
42 40
   Print usage statement
... ...
@@ -200,7 +200,7 @@ ENTRYPOINT.
200 200
                                'host': use the host shared memory,semaphores and message queues inside the container.  Note: the host mode gives the container full access to local shared memory and is therefore considered insecure.
201 201
 
202 202
 **-l**, **--label**=[]
203
-   Set meta data on the container (e.g., --label=com.example.key=value)
203
+   Set metadata on the container (e.g., --label com.example.key=value)
204 204
 
205 205
 **--label-file**=[]
206 206
    Read in a line delimited file of labels
... ...
@@ -59,7 +59,7 @@ pages:
59 59
 - ['userguide/dockerimages.md', 'User Guide', 'Working with Docker Images' ]
60 60
 - ['userguide/dockerlinks.md', 'User Guide', 'Linking containers together' ]
61 61
 - ['userguide/dockervolumes.md', 'User Guide', 'Managing data in containers' ]
62
-- ['userguide/labels-custom-metadata.md', 'User Guide', 'Labels - custom meta-data in Docker' ]
62
+- ['userguide/labels-custom-metadata.md', 'User Guide', 'Labels - custom metadata in Docker' ]
63 63
 - ['userguide/dockerrepos.md', 'User Guide', 'Working with Docker Hub' ]
64 64
 - ['userguide/level1.md', '**HIDDEN**' ]
65 65
 - ['userguide/level2.md', '**HIDDEN**' ]
... ...
@@ -71,9 +71,8 @@ This endpoint now returns `SystemTime`, `HttpProxy`,`HttpsProxy` and `NoProxy`.
71 71
 
72 72
 ### What's new
73 73
 
74
-**New!**
75
-Build now has support for `LABEL` command which can be used to add user data
76
-to an image.  For example you could add data describing the content of an image.
74
+The build supports `LABEL` command. Use this to add metadata
75
+to an image. For example you could add data describing the content of an image.
77 76
 
78 77
 `LABEL "com.example.vendor"="ACME Incorporated"`
79 78
 
... ...
@@ -91,7 +90,7 @@ You can set labels on container create describing the container.
91 91
 `GET /containers/json`
92 92
 
93 93
 **New!**
94
-This endpoint now returns the labels associated with each container (`Labels`).
94
+The endpoint returns the labels associated with the containers (`Labels`).
95 95
 
96 96
 `GET /containers/(id)/json`
97 97
 
... ...
@@ -195,8 +195,7 @@ Json Parameters:
195 195
 -   **OpenStdin** - Boolean value, opens stdin,
196 196
 -   **StdinOnce** - Boolean value, close stdin after the 1 attached client disconnects.
197 197
 -   **Env** - A list of environment variables in the form of `VAR=value`
198
--   **Labels** - A map of labels and their values that will be added to the
199
-        container. It should be specified in the form `{"name":"value"[,"name2":"value2"]}`
198
+-   **Labels** - Adds a map of labels that to a container. To specify a map: `{"key":"value"[,"key2":"value2"]}`
200 199
 -   **Cmd** - Command to run specified as a string or an array of strings.
201 200
 -   **Entrypoint** - Set the entrypoint for the container a a string or an array
202 201
       of strings
... ...
@@ -329,26 +329,26 @@ default specified in `CMD`.
329 329
 > the intended command for the image.
330 330
 
331 331
 ## LABEL
332
-   LABEL <key>=<value> <key>=<value> <key>=<value> ...
333 332
 
334
-The `LABEL` instruction allows you to add meta-data to the image your 
335
-`Dockerfile` is building. `LABEL` is specified as name value pairs. This data can
336
-be retrieved using the `docker inspect` command
333
+    LABEL <key>=<value> <key>=<value> <key>=<value> ...
337 334
 
338
-    LABEL com.example.label-without-value
339
-    LABEL com.example.label-with-value="foo"
340
-    LABEL version="1.0"
341
-    LABEL description="This my ACME image" vendor="ACME Products"
335
+The `LABEL` instruction adds metadata to an image. A `LABEL` is a
336
+key-value pair. To include spaces within a `LABEL` value, use quotes and
337
+blackslashes as you would in command-line parsing.
342 338
 
343
-As illustrated above, the `LABEL` instruction allows for multiple labels to be
344
-set at one time. Like command line parsing, quotes and backslashes can be used
345
-to include spaces within values.
339
+    LABEL "com.example.vendor"="ACME Incorporated"
346 340
 
347
-For example:
341
+An image can have more than one label. To specify multiple labels, separate each
342
+key-value pair by an EOL.
348 343
 
344
+    LABEL com.example.label-without-value
345
+    LABEL com.example.label-with-value="foo"
346
+    LABEL version="1.0"
349 347
     LABEL description="This text illustrates \
350 348
     that label-values can span multiple lines."
351 349
 
350
+To view an image's labels, use the `docker inspect` command.
351
+
352 352
 ## EXPOSE
353 353
 
354 354
     EXPOSE <port> [<port>...]
... ...
@@ -791,7 +791,7 @@ Creates a new container.
791 791
       -h, --hostname=""          Container host name
792 792
       -i, --interactive=false    Keep STDIN open even if not attached
793 793
       --ipc=""                   IPC namespace to use
794
-      -l, --label=[]             Set meta data on the container (e.g., --label=com.example.key=value)
794
+      -l, --label=[]             Set metadata on the container (e.g., --label=com.example.key=value)
795 795
       --label-file=[]            Read in a line delimited file of labels
796 796
       --link=[]                  Add link to another container
797 797
       --lxc-conf=[]              Add custom lxc options
... ...
@@ -1665,8 +1665,8 @@ removed before the image is removed.
1665 1665
       --link=[]                  Add link to another container
1666 1666
       --lxc-conf=[]              Add custom lxc options
1667 1667
       -m, --memory=""            Memory limit
1668
-      -l, --label=[]             Set meta data on the container (e.g., --label=com.example.key=value)
1669
-      --label-file=[]            Read in a line delimited file of labels
1668
+      -l, --label=[]             Set metadata on the container (e.g., --label=com.example.key=value)
1669
+      --label-file=[]            Read in a file of labels (EOL delimited)
1670 1670
       --mac-address=""           Container MAC address (e.g. 92:d0:c6:0a:29:33)
1671 1671
       --memory-swap=""           Total memory (memory + swap), '-1' to disable swap
1672 1672
       --name=""                  Assign a name to the container
... ...
@@ -1837,38 +1837,39 @@ An example of a file passed with `--env-file`
1837 1837
 
1838 1838
     $ sudo docker run --name console -t -i ubuntu bash
1839 1839
 
1840
-This will create and run a new container with the container name being
1841
-`console`.
1840
+A label is a a `key=value` pair that applies metadata to a container. To label a container with two labels:
1842 1841
 
1843 1842
     $ sudo docker run -l my-label --label com.example.foo=bar ubuntu bash
1844 1843
 
1845
-This sets two labels on the container. Label "my-label" doesn't have a value
1846
-specified and will default to "" (empty string) for its value. Both `-l` and 
1847
-`--label` can be repeated to add more labels. Label names are unique; if the same
1848
-label is specified multiple times, latter values overwrite the previous value.
1844
+The `my-label` key doesn't specify so the label defaults to an empty
1845
+string(`""`). To add multiple labels, repeat the label flag (`-l` or
1846
+`--label`).
1847
+
1848
+The `key=value` must be unique. If you specify the same key multiple times
1849
+with different values, each subsequent value overwrites the previous. Docker
1850
+applies the last `key=value` you supply.
1849 1851
 
1850
-Labels can also be loaded from a line delimited file of labels using the 
1851
-`--label-file` flag. The example below will load labels from a file named `labels`
1852
-in the current directory;
1852
+Use the `--label-file` flag to load multiple labels from a file. Delimit each
1853
+label in the file with an EOL mark. The example below loads labels from a
1854
+labels file in the current directory;
1853 1855
 
1854 1856
     $ sudo docker run --label-file ./labels ubuntu bash
1855 1857
 
1856
-The format of the labels-file is similar to that used for loading environment
1857
-variables (see `--label-file` above). An example of a file passed with `--label-file`;
1858
+The label-file format is similar to the format for loading environment variables
1859
+(see `--env-file` above). The following example illustrates a label-file format;
1858 1860
 
1859
-    $ cat ./labels
1860 1861
     com.example.label1="a label"
1861 1862
 
1862 1863
     # this is a comment
1863 1864
     com.example.label2=another\ label
1864 1865
     com.example.label3
1865 1866
 
1866
-Multiple label-files can be loaded by providing the `--label-file` multiple 
1867
+You can load multiple label-files by supplying the `--label-file` flag multiple
1867 1868
 times.
1868 1869
 
1869
-For additional information on working with labels, see 
1870
-[*Labels - custom meta-data in Docker*](/userguide/labels-custom-metadata/) in
1871
-the user guide.
1870
+For additional information on working with labels, see
1871
+[*Labels - custom metadata in Docker*](/userguide/labels-custom-metadata/) in
1872
+the Docker User Guide.
1872 1873
 
1873 1874
     $ sudo docker run --link /redis:redis --name console ubuntu bash
1874 1875
 
... ...
@@ -1,61 +1,67 @@
1
-page_title: Labels - custom meta-data in Docker
2
-page_description: Learn how to work with custom meta-data in Docker, using labels.
3
-page_keywords: Usage, user guide, labels, meta-data, docker, documentation, examples, annotating
1
+page_title: Labels - custom metadata in Docker
2
+page_description: Learn how to work with custom metadata in Docker, using labels.
3
+page_keywords: Usage, user guide, labels, metadata, docker, documentation, examples, annotating
4 4
 
5
-## Labels - custom meta-data in Docker
5
+## Labels - custom metadata in Docker
6 6
 
7
-Docker enables you to add meta-data to your images, containers, and daemons via
8
-labels. Meta-data can serve a wide range of uses ranging from adding notes or 
9
-licensing information to an image to identifying a host.
7
+You can add metadata to your images, containers, and daemons via
8
+labels. Metadata can serve a wide range of uses. Use them to add notes or
9
+licensing information to an image or to identify a host.
10 10
 
11
-Labels in Docker are implemented as `<key>` / `<value>` pairs and values are
12
-stored as *strings*.
11
+A label is a `<key>` / `<value>` pair. Docker stores the values as *strings*.
12
+You can specify multiple labels but each `<key>` / `<value>` must be unique.  If
13
+you specify the same `key` multiple times with different values, each subsequent
14
+value overwrites the previous. Docker applies the last `key=value` you supply.
13 15
 
14
->**note:** Support for daemon-labels was added in docker 1.4.1, labels on
15
->containers and images in docker 1.6.0
16
+>**note:** Support for daemon-labels was added in Docker 1.4.1. Labels on
17
+>containers and images are new in Docker 1.6.0
16 18
 
17 19
 ### Naming your labels - namespaces
18 20
 
19
-Docker puts no hard restrictions on the names you pick for your labels, however,
20
-it's easy for labels to "conflict".
21
-
22
-For example, you're building a tool that categorizes your images in 
23
-architectures, doing so by using an "architecture" label;
21
+Docker puts no hard restrictions on the label `key` you. However, labels can
22
+conflict. For example, you can categorize your images by using a chip "architecture"
23
+label:
24 24
 
25 25
     LABEL architecture="amd64"
26 26
 
27 27
     LABEL architecture="ARMv7"
28 28
 
29
-But a user decided to label images by Architectural style
29
+But a user can label images by building architectural style:
30 30
 
31 31
     LABEL architecture="Art Nouveau"
32 32
 
33
-To prevent such conflicts, Docker uses the convention to namespace label-names,
34
-using a reverse domain notation;
33
+To prevent such conflicts, Docker namespaces label keys using a reverse domain
34
+notation. This notation has the following guidelines:
35
+
35 36
 
37
+- All (third-party) tools should prefix their keys with the
38
+  reverse DNS notation of a domain controlled by the author. For
39
+  example, `com.example.some-label`.
36 40
 
37
-- All (third-party) tools should namespace (prefix) their labels with the 
38
-  reverse DNS notation of a domain controlled by the author of the tool. For 
39
-  example, "com.example.some-label".
40
-- Namespaced labels should only consist of lower-cased alphanumeric characters,
41
-  dots and dashes (in short, `[a-z0-9-.]`), should start *and* end with an alpha
42
-  numeric character, and may not contain consecutive dots or dashes.
43 41
 - The `com.docker.*`, `io.docker.*` and `com.dockerproject.*` namespaces are
44 42
   reserved for Docker's internal use.
45
-- Labels *without* namespace (dots) are reserved for CLI use. This allows end-
46
-  users to add meta-data to their containers and images, without having to type 
43
+
44
+- Keys should only consist of lower-cased alphanumeric characters,
45
+  dots and dashes (for example, `[a-z0-9-.]`)
46
+
47
+- Keys should start *and* end with an alpha numeric character
48
+
49
+- Keys may not contain consecutive dots or dashes.
50
+
51
+- Keys *without* namespace (dots) are reserved for CLI use. This allows end-
52
+  users to add metadata to their containers and images, without having to type
47 53
   cumbersome namespaces on the command-line.
48 54
 
49 55
 
50
-> **Note:** Even though Docker does not *enforce* you to use namespaces,
51
-> preventing to do so will likely result in conflicting usage of labels. 
52
-> If you're building a tool that uses labels, you *should* use namespaces
53
-> for your labels.
56
+These are guidelines and are not enforced. Docker does not *enforce* them.
57
+Failing following these guidelines can result in conflicting labels. If you're
58
+building a tool that uses labels, you *should* use namespaces for your label keys.
54 59
 
55 60
 
56 61
 ### Storing structured data in labels
57 62
 
58
-Labels can store any type of data, as long as its stored as a string. 
63
+Label values can contain any data type as long as the value can be stored as a
64
+string. For example, consider this JSON:
59 65
 
60 66
 
61 67
     {
... ...
@@ -68,31 +74,28 @@ Labels can store any type of data, as long as its stored as a string.
68 68
         "aNestedArray": ["a", "b", "c"]
69 69
     }
70 70
 
71
-Which can be stored in a label by serializing it to a string first;
71
+You can store this struct in a label by serializing it to a string first:
72 72
 
73 73
     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\"]}"
74 74
 
75
+While it is *possible* to store structured data in label values, Docker treats this
76
+data as a 'regular' string. This means that Docker doesn't offer ways to query
77
+(filter) based on nested properties.
75 78
 
76
-> **Note:** Although the example above shows it's *possible* to store structured 
77
-> data in labels, Docker does not treat this data any other way than a 'regular'
78
-> string. This means that Docker doesn't offer ways to query (filter) based on 
79
-> nested properties. If your tool needs to filter on nested properties, the 
80
-> tool itself should implement this.
79
+If your tool needs to filter on nested properties, the tool itself should
80
+implement this.
81 81
 
82 82
 
83 83
 ### Adding labels to images; the `LABEL` instruction
84 84
 
85
-Adding labels to your 
85
+Adding labels to an image:
86 86
 
87 87
 
88
-    LABEL [<namespace>.]<name>[=<value>] ...
88
+    LABEL [<namespace>.]<key>[=<value>] ...
89 89
 
90 90
 The `LABEL` instruction adds a label to your image, optionally setting its value.
91
-Quotes surrounding name and value are optional, but required if they contain
92
-white space characters. Alternatively, backslashes can be used.
93
-
94
-Label values only support strings
95
-
91
+Use surrounding quotes or backslashes for labels that contain
92
+white space character:
96 93
 
97 94
     LABEL vendor=ACME\ Incorporated
98 95
     LABEL com.example.version.is-beta
... ...
@@ -104,15 +107,19 @@ using this notation;
104 104
 
105 105
     LABEL com.example.version="0.0.1-beta" com.example.release-date="2015-02-12"
106 106
 
107
-Wrapping is allowed by using a backslash (`\`) as continuation marker;
107
+Wrapping is allowed by using a backslash (`\`) as continuation marker:
108 108
 
109 109
     LABEL vendor=ACME\ Incorporated \
110 110
           com.example.is-beta \
111 111
           com.example.version="0.0.1-beta" \
112 112
           com.example.release-date="2015-02-12"
113 113
 
114
+Docker recommends combining labels in a single `LABEL` instruction instead of
115
+using a `LABEL` instruction for each label. Each instruction in a Dockerfile
116
+produces a new layer that can result in an inefficient image if you use many
117
+labels.
114 118
 
115
-You can view the labels via `docker inspect`
119
+You can view the labels via the `docker inspect` command:
116 120
 
117 121
     $ docker inspect 4fa6e0f0c678
118 122
 
... ...
@@ -129,27 +136,21 @@ You can view the labels via `docker inspect`
129 129
 
130 130
     {"Vendor":"ACME Incorporated","com.example.is-beta":"","com.example.version":"0.0.1-beta","com.example.release-date":"2015-02-12"}
131 131
 
132
-> **note:** We recommend combining labels in a single `LABEl` instruction in
133
-> stead of using a `LABEL` instruction for each label. Each instruction in a
134
-> Dockerfile produces a new layer, which can result in an inefficient image if
135
-> many labels are used.
136 132
 
137
-### Querying labels
138 133
 
139
-Besides storing meta-data, labels can be used to filter your images and 
140
-containers.
134
+### Querying labels
141 135
 
142
-List all running containers that have a `com.example.is-beta` label;
136
+Besides storing metadata, you can filter images and labels by label. To list all
137
+running containers that have a `com.example.is-beta` label:
143 138
 
144 139
     # List all running containers that have a `com.example.is-beta` label
145 140
     $ docker ps --filter "label=com.example.is-beta"
146 141
 
147
-
148
-List all running containers with a "color" label set to "blue";
142
+List all running containers with a `color` label of `blue`:
149 143
 
150 144
     $ docker ps --filter "label=color=blue"
151 145
 
152
-List all images with "vendor" "ACME"
146
+List all images with `vendor` `ACME`:
153 147
 
154 148
     $ docker images --filter "label=vendor=ACME"
155 149
 
... ...
@@ -157,7 +158,6 @@ List all images with "vendor" "ACME"
157 157
 ### Daemon labels
158 158
 
159 159
 
160
-
161 160
     docker -d \
162 161
       --dns 8.8.8.8 \
163 162
       --dns 8.8.4.4 \
... ...
@@ -165,7 +165,7 @@ List all images with "vendor" "ACME"
165 165
       --label com.example.environment="production" \
166 166
       --label com.example.storage="ssd"
167 167
 
168
-And can be seen as part of the `docker info` output for the daemon;
168
+These labels appear as part of the `docker info` output for the daemon:
169 169
 
170 170
     docker -D info
171 171
     Containers: 12