Browse code

Updating with Sven's comments and other tweaks

Signed-off-by: Mary Anthony <mary@docker.com>

Mary Anthony authored on 2015/03/17 13:49:33
Showing 8 changed files
... ...
@@ -159,8 +159,12 @@ A Dockerfile is similar to a Makefile.
159 159
   LABEL "com.example.vendor"="ACME Incorporated"
160 160
   ```
161 161
 
162
-  An image can have more than one label. To specify multiple labels, separate each
163
-  key-value pair by a space.
162
+  An image can have more than one label. To specify multiple labels, separate
163
+  each key-value pair by a space. 
164
+  
165
+  Labels are additive including `LABEL`s in `FROM` images. As the system
166
+  encounters and then applies a new label, new `key`s override any previous
167
+  labels with identical keys.
164 168
 
165 169
   To display an image's labels, use the `docker inspect` command.
166 170
 
... ...
@@ -290,20 +294,22 @@ A Dockerfile is similar to a Makefile.
290 290
 
291 291
 **ONBUILD**
292 292
   -- `ONBUILD [INSTRUCTION]`
293
-  The **ONBUILD** instruction adds a trigger instruction to the image, which is 
294
-  executed at a later time, when the image is used as the base for another
295
-  build. The trigger is executed in the context of the downstream build, as
296
-  if it had been inserted immediately after the **FROM** instruction in the
297
-  downstream Dockerfile.  Any build instruction can be registered as a
298
-  trigger.  This is useful if you are building an image to be
299
-  used as a base for building other images, for example an application build
300
-  environment or a daemon to be customized with a user-specific
301
-  configuration.  For example, if your image is a reusable python
302
-  application builder, it requires application source code to be
303
-  added in a particular directory, and might require a build script
304
-  to be called after that. You can't just call **ADD** and **RUN** now, because
305
-  you don't yet have access to the application source code, and it
306
-  is different for each application build.
293
+  The **ONBUILD** instruction adds a trigger instruction to an image. The
294
+  trigger is executed at a later time, when the image is used as the base for
295
+  another build. Docker executes the trigger in the context of the downstream
296
+  build, as if the trigger existed immediately after the **FROM** instruction in
297
+  the downstream Dockerfile.
298
+
299
+  You can register any build instruction as a trigger. A trigger is useful if
300
+  you are defining an image to use as a base for building other images. For
301
+  example, if you are defining an application build environment or a daemon that
302
+  is customized with a user-specific configuration.  
303
+  
304
+  Consider an image intended as a reusable python application builder. It must
305
+  add application source code to a particular directory, and might need a build
306
+  script called after that. You can't just call **ADD** and **RUN** now, because
307
+  you don't yet have access to the application source code, and it is different
308
+  for each application build.
307 309
 
308 310
   -- Providing application developers with a boilerplate Dockerfile to copy-paste
309 311
   into their application is inefficient, error-prone, and
... ...
@@ -22,7 +22,7 @@ Using an existing container's name or ID you can create a new image.
22 22
 
23 23
 **-c** , **--change**=[]
24 24
    Apply specified Dockerfile instructions while committing the image
25
-   Supported Dockerfile instructions: CMD, ENTRYPOINT, ENV, EXPOSE, ONBUILD, USER, VOLUME, WORKDIR
25
+   Supported Dockerfile instructions: ADD|CMD|ENTRYPOINT|ENV|EXPOSE|FROM|MAINTAINER|RUN|USER|LABEL|VOLUME|WORKDIR|COPY
26 26
 
27 27
 **--help**
28 28
   Print usage statement
... ...
@@ -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 metadata on the container (e.g., --label=com.example.key=value)
108
+   Adds metadata to a container (e.g., --label=com.example.key=value)
109 109
 
110 110
 **--label-file**=[]
111
-   Read in a file of labels (EOL delimited)
111
+   Read labels from a file. Delimit each label with an EOL.
112 112
 
113 113
 **--link**=[]
114 114
    Add link to another container in the form of <name or id>:alias
... ...
@@ -13,7 +13,7 @@ URL|- [REPOSITORY[:TAG]]
13 13
 # OPTIONS
14 14
 **-c**, **--change**=[]
15 15
    Apply specified Dockerfile instructions while importing the image
16
-   Supported Dockerfile instructions: CMD, ENTRYPOINT, ENV, EXPOSE, ONBUILD, USER, VOLUME, WORKDIR
16
+   Supported Dockerfile instructions: `ADD`|`CMD`|`ENTRYPOINT`|`ENV`|`EXPOSE`|`FROM`|`MAINTAINER`|`RUN`|`USER`|`LABEL`|`VOLUME`|`WORKDIR`|`COPY`
17 17
 
18 18
 # DESCRIPTION
19 19
 Create a new filesystem image from the contents of a tarball (`.tar`,
... ...
@@ -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 metadata in Docker' ]
62
+- ['userguide/labels-custom-metadata.md', 'User Guide', 'Apply custom metadata' ]
63 63
 - ['userguide/dockerrepos.md', 'User Guide', 'Working with Docker Hub' ]
64 64
 - ['userguide/level1.md', '**HIDDEN**' ]
65 65
 - ['userguide/level2.md', '**HIDDEN**' ]
... ...
@@ -347,6 +347,15 @@ key-value pair by an EOL.
347 347
     LABEL description="This text illustrates \
348 348
     that label-values can span multiple lines."
349 349
 
350
+Docker recommends combining labels in a single `LABEL` instruction where
351
+possible. Each `LABEL` instruction produces a new layer which can result in an
352
+inefficient image if you use many labels. This example results in four image
353
+layers. 
354
+    
355
+Labels are additive including `LABEL`s in `FROM` images. As the system
356
+encounters and then applies a new label, new `key`s override any previous labels
357
+with identical keys.    
358
+
350 359
 To view an image's labels, use the `docker inspect` command.
351 360
 
352 361
 ## EXPOSE
... ...
@@ -749,8 +749,7 @@ If this behavior is undesired, set the 'p' option to false.
749 749
 
750 750
 The `--change` option will apply `Dockerfile` instructions to the image
751 751
 that is created.
752
-Supported `Dockerfile` instructions: `CMD`, `ENTRYPOINT`, `ENV`, `EXPOSE`,
753
-`ONBUILD`, `USER`, `VOLUME`, `WORKDIR`
752
+Supported `Dockerfile` instructions: `ADD`|`CMD`|`ENTRYPOINT`|`ENV`|`EXPOSE`|`FROM`|`MAINTAINER`|`RUN`|`USER`|`LABEL`|`VOLUME`|`WORKDIR`|`COPY`
754 753
 
755 754
 #### Commit a container
756 755
 
... ...
@@ -1864,22 +1863,23 @@ A label is a a `key=value` pair that applies metadata to a container. To label a
1864 1864
 
1865 1865
     $ sudo docker run -l my-label --label com.example.foo=bar ubuntu bash
1866 1866
 
1867
-The `my-label` key doesn't specify so the label defaults to an empty
1868
-string(`""`). To add multiple labels, repeat the label flag (`-l` or
1869
-`--label`).
1867
+The `my-label` key doesn't specify a value so the label defaults to an empty
1868
+string(`""`). To add multiple labels, repeat the label flag (`-l` or `--label`).
1870 1869
 
1871
-The `key=value` must be unique. If you specify the same key multiple times
1872
-with different values, each subsequent value overwrites the previous. Docker
1873
-applies the last `key=value` you supply.
1870
+The `key=value` must be unique to avoid overwriting the label value. If you
1871
+specify labels with identical keys but different values, each subsequent value
1872
+overwrites the previous. Docker uses the last `key=value` you supply.
1874 1873
 
1875 1874
 Use the `--label-file` flag to load multiple labels from a file. Delimit each
1876 1875
 label in the file with an EOL mark. The example below loads labels from a
1877
-labels file in the current directory;
1876
+labels file in the current directory:
1878 1877
 
1879 1878
     $ sudo docker run --label-file ./labels ubuntu bash
1880 1879
 
1881
-The label-file format is similar to the format for loading environment variables
1882
-(see `--env-file` above). The following example illustrates a label-file format;
1880
+The label-file format is similar to the format for loading environment
1881
+variables. (Unlike environment variables, labels are not visislbe to processes
1882
+running inside a container.) The following example illustrates a label-file
1883
+format:
1883 1884
 
1884 1885
     com.example.label1="a label"
1885 1886
 
... ...
@@ -1887,12 +1887,11 @@ The label-file format is similar to the format for loading environment variables
1887 1887
     com.example.label2=another\ label
1888 1888
     com.example.label3
1889 1889
 
1890
-You can load multiple label-files by supplying the `--label-file` flag multiple
1891
-times.
1890
+You can load multiple label-files by supplying multiple  `--label-file` flags. 
1892 1891
 
1893
-For additional information on working with labels, see
1894
-[*Labels - custom metadata in Docker*](/userguide/labels-custom-metadata/) in
1895
-the Docker User Guide.
1892
+For additional information on working with labels, see [*Labels - custom
1893
+metadata in Docker*](/userguide/labels-custom-metadata/) in the Docker User
1894
+Guide.
1896 1895
 
1897 1896
     $ sudo docker run --link /redis:redis --name console ubuntu bash
1898 1897
 
... ...
@@ -1,26 +1,27 @@
1
-page_title: Labels - custom metadata in Docker
1
+page_title: Apply custom metadata
2 2
 page_description: Learn how to work with custom metadata in Docker, using labels.
3 3
 page_keywords: Usage, user guide, labels, metadata, docker, documentation, examples, annotating
4 4
 
5
-## Labels - custom metadata in Docker
5
+# Apply custom metadata
6 6
 
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
7
+You can apply metadata to your images, containers, or daemons via
8
+labels. Metadata can serve a wide range of uses. Use labels to add notes or
9 9
 licensing information to an image or to identify a host.
10 10
 
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.
11
+A label is a `<key>` / `<value>` pair. Docker stores the label values as
12
+*strings*. You can specify multiple labels but each `<key>` / `<value>` must be
13
+unique to avoid overwriting. If you specify the same `key` several times but with
14
+different values, newer labels overwrite previous labels. Docker uses
15
+the last `key=value` you supply.
15 16
 
16
->**note:** Support for daemon-labels was added in Docker 1.4.1. Labels on
17
+>**Note:** Support for daemon-labels was added in Docker 1.4.1. Labels on
17 18
 >containers and images are new in Docker 1.6.0
18 19
 
19
-### Naming your labels - namespaces
20
+## Label keys (namespaces)
20 21
 
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:
22
+Docker puts no hard restrictions on the label `key` you. However, labels with
23
+simple keys can conflict. For example, you can categorize your images by using a
24
+chip "architecture" label:
24 25
 
25 26
     LABEL architecture="amd64"
26 27
 
... ...
@@ -30,9 +31,8 @@ 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 namespaces label keys using a reverse domain
34
-notation. This notation has the following guidelines:
35
-
33
+To prevent naming conflicts, Docker namespaces label keys using a reverse domain
34
+notation. Use the following guidelines to name your keys:
36 35
 
37 36
 - All (third-party) tools should prefix their keys with the
38 37
   reverse DNS notation of a domain controlled by the author. For
... ...
@@ -49,19 +49,19 @@ notation. This notation has the following guidelines:
49 49
 - Keys may not contain consecutive dots or dashes.
50 50
 
51 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
52
+  users to add metadata to their containers and images without having to type
53 53
   cumbersome namespaces on the command-line.
54 54
 
55 55
 
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.
56
+These are guidelines and Docker does not *enforce* them. Failing following these
57
+guidelines can result in conflicting labels. If you're building a tool that uses
58
+labels, you *should* use namespaces for your label keys.
59 59
 
60 60
 
61
-### Storing structured data in labels
61
+## Store structured data in labels
62 62
 
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:
63
+Label values can contain any data type that can be stored as a string. For
64
+example, consider this JSON:
65 65
 
66 66
 
67 67
     {
... ...
@@ -78,15 +78,13 @@ You can store this struct in a label by serializing it to a string first:
78 78
 
79 79
     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\"]}"
80 80
 
81
-While it is *possible* to store structured data in label values, Docker treats this
82
-data as a 'regular' string. This means that Docker doesn't offer ways to query
83
-(filter) based on nested properties.
84
-
85
-If your tool needs to filter on nested properties, the tool itself should
86
-implement this.
81
+While it is *possible* to store structured data in label values, Docker treats
82
+this data as a 'regular' string. This means that Docker doesn't offer ways to
83
+query (filter) based on nested properties. If your tool needs to filter on
84
+nested properties, the tool itself should implement this.
87 85
 
88 86
 
89
-### Adding labels to images; the `LABEL` instruction
87
+## Add labels to images; the `LABEL` instruction
90 88
 
91 89
 Adding labels to an image:
92 90
 
... ...
@@ -103,7 +101,7 @@ white space character:
103 103
     LABEL com.example.release-date="2015-02-12"
104 104
 
105 105
 The `LABEL` instruction supports setting multiple labels in a single instruction
106
-using this notation;
106
+using this notation:
107 107
 
108 108
     LABEL com.example.version="0.0.1-beta" com.example.release-date="2015-02-12"
109 109
 
... ...
@@ -114,10 +112,9 @@ Wrapping is allowed by using a backslash (`\`) as continuation marker:
114 114
           com.example.version="0.0.1-beta" \
115 115
           com.example.release-date="2015-02-12"
116 116
 
117
-Docker recommends combining labels in a single `LABEL` instruction instead of
118
-using a `LABEL` instruction for each label. Each instruction in a Dockerfile
119
-produces a new layer that can result in an inefficient image if you use many
120
-labels.
117
+Docker recommends you add multiple labels in a single `LABEL` instruction. Using
118
+individual instructions for each label can result in an inefficient image. This
119
+is because each `LABEL` instruction in a Dockerfile produces a new IMAGE layer. 
121 120
 
122 121
 You can view the labels via the `docker inspect` command:
123 122
 
... ...
@@ -137,11 +134,10 @@ You can view the labels via the `docker inspect` command:
137 137
     {"Vendor":"ACME Incorporated","com.example.is-beta":"","com.example.version":"0.0.1-beta","com.example.release-date":"2015-02-12"}
138 138
 
139 139
 
140
+## Query labels
140 141
 
141
-### Querying labels
142
-
143
-Besides storing metadata, you can filter images and labels by label. To list all
144
-running containers that have a `com.example.is-beta` label:
142
+Besides storing metadata, you can filter images and containers by label. To list all
143
+running containers that the `com.example.is-beta` label:
145 144
 
146 145
     # List all running containers that have a `com.example.is-beta` label
147 146
     $ docker ps --filter "label=com.example.is-beta"
... ...
@@ -155,7 +151,7 @@ List all images with `vendor` `ACME`:
155 155
     $ docker images --filter "label=vendor=ACME"
156 156
 
157 157
 
158
-### Daemon labels
158
+## Daemon labels
159 159
 
160 160
 
161 161
     docker -d \