<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>If you do not want to use volumes, you can save your container at a specific time by using <code>docker commit --change &quot;added some changes to my container&quot; &lt;container_id&gt; repo/image:tag</code></p>
<p>The new image will contains all filesystem of your current container.</p>
<p>That being said, not using volume has several disadvantages:</p>
<p>By default all files created inside a container are stored on a writable container layer. This means that:</p>
<blockquote>
<p>The data <strong>doesn’t persist when that container is no longer running</strong>, and it can be <strong>difficult to get the data out of the container if another process needs it</strong>.
A container’s writable layer is <strong>tightly coupled to the host machine</strong> where the container is running. You can’t easily move the data somewhere else.
Writing into a container’s writable layer requires a <strong>storage driver to manage the filesystem</strong>. The storage driver provides a union filesystem, using the Linux kernel. This <strong>extra abstraction reduces performance as compared to using data volumes, which write directly to the host filesystem</strong>.</p>
</blockquote>
<p>So your best choice is to use volume !
Now you can choose between different kinds:</p>
<ul>
<li>bind mounts</li>
<li>named volumes</li>
</ul>
<blockquote>
<p>While bind mounts are dependent on the directory structure of the host machine, volumes are completely managed by Docker. Volumes have several advantages over bind mounts:</p>
<p>Volumes are easier to back up or migrate than bind mounts.
You can manage volumes using Docker CLI commands or the Docker API.
Volumes work on both Linux and Windows containers.
Volumes can be more safely shared among multiple containers.
Volume drivers let you store volumes on remote hosts or cloud providers, to encrypt the contents of volumes, or to add other functionality.
New volumes can have their content pre-populated by a container.</p>
</blockquote>
<p>Read the documentation to understand volume's features better : <a href="https://docs.docker.com/storage/volumes/" rel="nofollow noreferrer">https://docs.docker.com/storage/volumes/</a></p>
