Browse code

Tell users about how VOLUME initializes the new mount point/volume

Signed-off-by: Doug Davis <dug@us.ibm.com>

Doug Davis authored on 2015/03/06 23:36:23
Showing 3 changed files
... ...
@@ -325,16 +325,20 @@ read-write. See examples.
325 325
 **--volumes-from**=[]
326 326
    Mount volumes from the specified container(s)
327 327
 
328
-   Will mount volumes from the specified container identified by container-id.
329
-Once a volume is mounted in a one container it can be shared with other
330
-containers using the **--volumes-from** option when running those other
331
-containers. The volumes can be shared even if the original container with the
332
-mount is not running.
333
-
334
-   The container ID may be optionally suffixed with :ro or
335
-:rw to mount the volumes in read-only or read-write mode, respectively. By
336
-default, the volumes are mounted in the same mode (read write or read only) as
337
-the reference container.
328
+   Mounts already mounted volumes from a source container onto another
329
+   container. You must supply the source's container-id. To share 
330
+   a volume, use the **--volumes-from** option when running
331
+   the target container. You can share volumes even if the source container 
332
+   is not running.
333
+
334
+   By default, Docker mounts the volumes in the same mode (read-write or 
335
+   read-only) as it is mounted in the source container. Optionally, you 
336
+   can change this by suffixing the container-id with either the `:ro` or 
337
+   `:rw ` keyword.
338
+
339
+   If the location of the volume from the source container overlaps with
340
+   data residing on a target container, then the volume hides
341
+   that data on the target.
338 342
 
339 343
 **-w**, **--workdir**=""
340 344
    Working directory inside the container
... ...
@@ -777,14 +777,28 @@ If you then run `docker stop test`, the container will not exit cleanly - the
777 777
 
778 778
     VOLUME ["/data"]
779 779
 
780
-The `VOLUME` instruction will create a mount point with the specified name
781
-and mark it as holding externally mounted volumes from native host or other
780
+The `VOLUME` instruction creates a mount point with the specified name
781
+and marks it as holding externally mounted volumes from native host or other
782 782
 containers. The value can be a JSON array, `VOLUME ["/var/log/"]`, or a plain
783 783
 string with multiple arguments, such as `VOLUME /var/log` or `VOLUME /var/log
784 784
 /var/db`.  For more information/examples and mounting instructions via the
785
-Docker client, refer to [*Share Directories via Volumes*](/userguide/dockervolumes/#volume)
785
+Docker client, refer to 
786
+[*Share Directories via Volumes*](/userguide/dockervolumes/#volume)
786 787
 documentation.
787 788
 
789
+The `docker run` command initializes the newly created volume with any data 
790
+that exists at the specified location within the base image. For example, 
791
+consider the following Dockerfile snippet:
792
+
793
+    FROM ubuntu
794
+    RUN mkdir /myvol
795
+    RUN echo "hello world" > /myvol/greating
796
+    VOLUME /myvol
797
+
798
+This Dockerfile results in an image that causes `docker run`, to
799
+create a new mount point at `/myvol` and copy the  `greating` file 
800
+into the newly created volume.
801
+
788 802
 > **Note**:
789 803
 > The list is parsed as a JSON array, which means that
790 804
 > you must use double-quotes (") around words not single-quotes (').
... ...
@@ -21,19 +21,21 @@ Docker.
21 21
 
22 22
 A *data volume* is a specially-designated directory within one or more
23 23
 containers that bypasses the [*Union File
24
-System*](/terms/layer/#union-file-system) to provide several useful features for
25
-persistent or shared data:
24
+System*](/terms/layer/#union-file-system). Data volumes provide several 
25
+useful features for persistent or shared data:
26 26
 
27
-- Volumes are initialized when a container is created
28
-- Data volumes can be shared and reused between containers
29
-- Changes to a data volume are made directly
30
-- Changes to a data volume will not be included when you update an image
31
-- Data volumes persist even if the container itself is deleted
27
+- Volumes are initialized when a container is created. If the container's
28
+  base image contains data at the specified mount point, that data is 
29
+  copied into the new volume.
30
+- Data volumes can be shared and reused among containers.
31
+- Changes to a data volume are made directly.
32
+- Changes to a data volume will not be included when you update an image.
33
+- Data volumes persist even if the container itself is deleted.
32 34
 
33 35
 Data volumes are designed to persist data, independent of the container's life 
34
-cycle. Docker will therefore *never* automatically delete volumes when you remove 
35
-a container, nor will it "garbage collect" volumes that are no longer referenced 
36
-by a container.
36
+cycle. Docker therefore *never* automatically delete volumes when you remove 
37
+a container, nor will it "garbage collect" volumes that are no longer 
38
+referenced by a container.
37 39
 
38 40
 ### Adding a data volume
39 41
 
... ...
@@ -132,6 +134,11 @@ And another:
132 132
 
133 133
     $ sudo docker run -d --volumes-from dbdata --name db2 training/postgres
134 134
 
135
+In this case, if the `postgres` image contained a directory called `/dbdata`
136
+then mounting the volumes from the `dbdata` container hides the
137
+`/dbdata` files from the `postgres` image. The result is only the files
138
+from the `dbdata` container are visible.
139
+
135 140
 You can use multiple `--volumes-from` parameters to bring together multiple data
136 141
 volumes from multiple containers.
137 142