title: In Docker, how can I share files between containers and then save them to an image?
body: <p>I want to commit the data in a container's shared volume to an image. I cannot seem to do it? I kind of get the impression this perhaps is not possible in Docker but that seems totally at odds with the whole philosophy of not leaving data on the host so part of me thinks there must be a way to do this. </p>
  
  <h1>1. Terminal 1</h1>
  
  <p>Start up a container in Terminal 1 with a volume.</p>
  
  <pre><code>$ docker run -it -v /data ubuntu:14.10 /bin/bash
  root@19fead4f6a68:/# echo "Hello Docker Volumes." &gt; /data/foo.txt
  </code></pre>
  
  <h1>2. Terminal 2</h1>
  
  <p>Start up a second container in Terminal 2 the file from container 1 is there so docker volumes are all working.</p>
  
  <pre><code>$ docker run -it --volumes-from 19fead4f6a68 ubuntu:14.10 /bin/bash
  
  root@5c7cdbfc67d8:/# cat /data/foo.txt
  Hello Docker Volumes.
  </code></pre>
  
  <h1>3. Terminal 3</h1>
  
  <p>My understanding is that I can only commit diffs to images so I check what the diffs are on both the containers. For some bizarre reason my changes do not show up!??</p>
  
  <pre><code>$ docker diff 19fead4f6a68
  A /data
  
  $ docker diff 5c7cdbfc67d8
  A /data
  </code></pre>
  
  <h1>4. Back in Terminal 1</h1>
  
  <p>I create a file outside of the volume folder</p>
  
  <pre><code> root@19fead4f6a68:/# echo "Docker you are a very strange beast...." &gt; /var/beast.txt
  </code></pre>
  
  <h1>5. Back in Terminal 3</h1>
  
  <p>We now have some changes we can commit although I am rather frustrated as this is not the data from the volume I needed to share with my other container.</p>
  
  <pre><code>$ docker diff 19fead4f6a68
  A /data
  C /var
  A /var/beast.txt
  </code></pre>
  
  <p>Clearly this is by design. Anyone have any ideas as to why docker don't allow me to save volume data to a commit? Is there anyway at all to share files between containers and then save them to an image? I feel like there must be something I am missing? Especially to the ends of sharing data whilst avoiding host dependencies.</p>