title: Script to clone/snapshot Docker Containers including their Data?
body: <p>I would like to clone a dockerized application including all its data, which uses three containers in this example: 1) a web application container such as a CMS, 2) a database container and 3) a data-volume container (using docker volumes).</p>
  
  <p>With docker-compose, I can easily create identical instances of these containers with just the initial data. But what, if I want to clone a set of running containers on the same server, including all its accumulated data, in a similar way as I would clone a KVM container? With KVM I would suspend or shutdown the VM, clone with something like virt-clone and then start the cloned guest, which has all the same data as the original.</p>
  
  <p>One use case would be to create a clone/snapshot of a running development web-server before making major changes or before installing new versions of plugins.</p>
  
  <p>With Docker, this does not seem to be so straightforward, as data is not automatically copied together with its container. Ideally I would like to do something simple like <code>docker-compose clone</code> and end up with a second set of containers identical to the first, including all their data. Neither Docker nor docker-compose provides a clone command (as of version 1.8), thus I would need to consider various approaches, like backing up &amp; restoring the data/database or using a third party tool like Flocker.</p>
  
  <p>Related to this is the question on how to do something similar to KVM snapshots of a dockerized app, with the ability to easily return to a previous state. Preferably the cloning, snapshotting and reverting should be possible with minimal downtime. </p>
  
  <p>What would be the preferred Docker way of accomplishing these things?</p>
  
  <p>Edit: Based on the first answer, I will make my question a little more specific in order to hopefully arrive at programmatic steps to be able to do something like <code>docker-compose-clone</code> and <code>docker-compose-snapshot</code> using a bash or python script. Cloning the content of the docker volumes seems to be the key to this, as the containers themselves are basically cloned each time I run docker-compose on the same yaml file. </p>
  
  <p>Generally my full-clone script would need to </p>
  
  <ol>
  <li>duplicate the directory containing the docker-compose file</li>
  <li>temporarily stop the containers</li>
  <li>create (but not necessarily run) the second set of containers</li>
  <li><em><strong>determine the data-volumes to be duplicated</strong></em></li>
  <li>backup these data-volumes </li>
  <li>restore the data-volumes into the cloned data container</li>
  <li><p>start the second set of containers</p>
  
  <ul>
  <li><p>Would this be the correct way to go about it and how should I implement this? I'm especially not sure on how to do step 4 (<em>determine the data-volumes to be duplicated</em>) in a script, as the command <code>docker volume ls</code> will only be available in Docker 1.9. </p></li>
  <li><p>How could I do something similar to KVM snapshots using this approach? (possibly using COW filesystem features from ZFS, which my Docker install is already using).</p></li>
  </ul></li>
  </ol>