<p>I am aware that the general wisdom when using docker is to move data out of the container and use volumes instead.</p>

<p>But I am trying to create a system that provides a one-click, completely containerized installation method, and saying "you should install mongodb first on your computer" is not an option.</p>

<p>So the current solution is to keep the data itself in the container (MongoDB for example), but I am now looking for ways to back up a snapshot of the container itself every now and then, so that I can instantly spawn up an identical container from scratch when one goes down.</p>

<p>How can I achieve this?</p>

<p>You could export and import the docker container easily.</p>

<p>An export whole container in the tar file</p>

<pre><code>docker export docker_container_name &gt; latest.tar
</code></pre>

<p>Import Docker container and run it</p>

<pre><code>cat exampleimage.tar | docker import - exampleimagelocal:new
</code></pre>

<p>Helpful link - <a href="https://docs.docker.com/engine/reference/commandline/export/#usage" rel="nofollow noreferrer">Docker export</a>     <a href="https://docs.docker.com/engine/reference/commandline/import/#examples" rel="nofollow noreferrer">Docker Import</a></p>

<p>If you want to export Docker image, then</p>

<pre><code>docker save -o image.tar Docker_Image_Name
</code></pre>

<p>Import Docker Image</p>

<pre><code>docker load -i image.tar
</code></pre>

<p>and then run docker images.</p>

<p>I think you could achieve by doing the above mostly you need to use the first approach, export docker container and deploy whenever you need it, it will contain your old data.</p>
