I was reading the documentation at https://memgraph.com/docs/memgraph/how-to-guides/work-with-docker and there I found the info that I need to create volume if I want to keep the data (-v mg_lib:/var/lib/memgraph
).
On another place (https://memgraph.com/docs/memgraph/2.5.0/reference-guide/backup#snapshots) I've found the following info: Memgraph periodically takes snapshots during runtime. When a snapshot is triggered, the entire data storage is written to the drive. On startup, the database state is recovered from the most recent snapshot file.
If the snapshots are created why would I need volume to keep my data? Is creating volume redundant?
Creating a Docker volume and having Memgraph create snapshots are two separate aspects of managing data persistence in Memgraph. Docker volumes are used for data persistence beyond the lifecycle of the container and Memgraph snapshots are used for faster recovery and backup.
Docker volume is essentially a mechanism provided by Docker that allows data to persist beyond the lifecycle of a single container. When a Docker container stops or is deleted, any data that was written to the file system inside that container is lost. By mapping a directory inside the container to a Docker volume on the host system, you're ensuring that data persists even if the container is stopped or removed.
Memgraph snapshots are a feature of the Memgraph database system itself. They provide a mechanism for periodically storing the state of the database to disk. This can help improve recovery time in case of a crash, and can also be used as a form of backup.
If Memgraph is running inside a Docker container and is taking snapshots, but there's no Docker volume set up, then those snapshots will be stored inside the container's filesystem. If that container is stopped or deleted, those snapshots (along with any other data) will be lost, because they're not persistent beyond the lifecycle of the container.
So, in this context, creating a Docker volume isn't redundant. It's actually necessary to ensure that the snapshots (and other data) persist beyond the lifecycle of the container. That's why the documentation instructs to map the Memgraph data directory to a Docker volume. This way, even if the container stops or is deleted, the data, including snapshots, will still be available on the host system.