Browse code

Merge pull request #3389 from SvenDowideit/3366-simplify-volumes-documentation

simplify the volumes documentation and mention more details

Andy Rothfusz authored on 2014/01/03 09:29:09
Showing 1 changed files
... ...
@@ -30,35 +30,58 @@ Each container can have zero or more data volumes.
30 30
 Getting Started
31 31
 ...............
32 32
 
33
-Using data volumes is as simple as adding a new flag: ``-v``. The
34
-parameter ``-v`` can be used more than once in order to create more
35
-volumes within the new container. The example below shows the
36
-instruction to create a container with two new volumes::
33
+Using data volumes is as simple as adding a ``-v`` parameter to the ``docker run`` 
34
+command. The ``-v`` parameter can be used more than once in order to 
35
+create more volumes within the new container. To create a new container with 
36
+two new volumes::
37 37
 
38
-  docker run -v /var/volume1 -v /var/volume2 shykes/couchdb
38
+  $ docker run -v /var/volume1 -v /var/volume2 busybox true
39 39
 
40
-For a Dockerfile, the VOLUME instruction will add one or more new
41
-volumes to any container created from the image::
40
+This command will create the new container with two new volumes that 
41
+exits instantly (``true`` is pretty much the smallest, simplest program 
42
+that you can run). Once created you can mount its volumes in any other 
43
+container using the ``-volumes-from`` option; irrespecive of whether the
44
+container is running or not. 
42 45
 
43
-  VOLUME ["/var/volume1", "/var/volume2"]
46
+Or, you can use the VOLUME instruction in a Dockerfile to add one or more new
47
+volumes to any container created from that image::
44 48
 
49
+  # BUILD-USING:        docker build -t data .
50
+  # RUN-USING:          docker run -name DATA data 
51
+  FROM          busybox
52
+  VOLUME        ["/var/volume1", "/var/volume2"]
53
+  CMD           ["/usr/bin/true"]
45 54
 
46
-Mount Volumes from an Existing Container:
55
+Creating and mounting a Data Volume Container
56
+---------------------------------------------
57
+
58
+If you have some persistent data that you want to share between containers, 
59
+or want to use from non-persistent containers, its best to create a named
60
+Data Volume Container, and then to mount the data from it.
61
+
62
+Create a named container with volumes to share (``/var/volume1`` and ``/var/volume2``)::
63
+
64
+  $ docker run -v /var/volume1 -v /var/volume2 -name DATA busybox true
65
+
66
+Then mount those data volumes into your application containers::
47 67
 
48
-The command below creates a new container which is running as daemon
49
-``-d`` and with one volume ``/var/lib/couchdb``::
68
+  $ docker run -t -i -rm -volumes-from DATA -name client1 ubuntu bash
50 69
 
51
-  COUCH1=$(sudo docker run -d -v /var/lib/couchdb shykes/couchdb:2013-05-03)
70
+You can use multiple ``-volumes-from`` parameters to bring together multiple 
71
+data volumes from multiple containers. 
52 72
 
53
-From the container id of that previous container ``$COUCH1`` it's
54
-possible to create new container sharing the same volume using the
55
-parameter ``-volumes-from container_id``::
73
+Interestingly, you can mount the volumes that came from the ``DATA`` container in 
74
+yet another container via the ``client1`` middleman container::
56 75
 
57
-  COUCH2=$(sudo docker run -d -volumes-from $COUCH1 shykes/couchdb:2013-05-03)
76
+  $ docker run -t -i -rm -volumes-from client1 ubuntu -name client2 bash
58 77
 
59
-Now, the second container has the all the information from the first volume.
78
+This allows you to abstract the actual data source from users of that data, 
79
+similar to :ref:`ambassador_pattern_linking <ambassador_pattern_linking>`.
60 80
 
81
+If you remove containers that mount volumes, including the initial DATA container, 
82
+or the middleman, the volumes will not be deleted until there are no containers still
83
+referencing those volumes. This allows you to upgrade, or effectivly migrate data volumes
84
+between containers.
61 85
 
62 86
 Mount a Host Directory as a Container Volume:
63 87
 ---------------------------------------------
... ...
@@ -68,13 +91,13 @@ Mount a Host Directory as a Container Volume:
68 68
   -v=[]: Create a bind mount with: [host-dir]:[container-dir]:[rw|ro].
69 69
   If "host-dir" is missing, then docker creates a new volume.
70 70
 
71
-This is not available for a Dockerfile due the portability and sharing
72
-purpose of it. The [host-dir] volumes is something 100% host dependent
73
-and will break on any other machine.
71
+This is not available from a Dockerfile as it makes the built image less portable
72
+or shareable. [host-dir] volumes are 100% host dependent and will break on any 
73
+other machine.
74 74
 
75 75
 For example::
76 76
 
77
-  sudo docker run -v /var/logs:/var/host_logs:ro shykes/couchdb:2013-05-03
77
+  sudo docker run -v /var/logs:/var/host_logs:ro ubuntu bash
78 78
 
79 79
 The command above mounts the host directory ``/var/logs`` into the
80 80
 container with read only permissions as ``/var/host_logs``.
... ...
@@ -87,3 +110,6 @@ Known Issues
87 87
 * :issue:`2702`: "lxc-start: Permission denied - failed to mount"
88 88
   could indicate a permissions problem with AppArmor. Please see the
89 89
   issue for a workaround.
90
+* :issue:`2528`:  the busybox container is used to make the resulting container as small and
91
+  simple as possible - whenever you need to interact with the data in the volume
92
+  you mount it into another container.