I have followed the documentation, and now I have started a mongodb container as follows:
docker run --rm -d --network ahem-mongo -p 27017:27017 \ --mount type=volume,source=mongodb.data,target=/data \ --env-file /root/.env.mongodb --name mongodb mongo
My mongodb container with persistent storage seems to run fine:
root@d1379ea48a72:/# df -h Filesystem Size Used Avail Use% Mounted on overlay 30G 9.0G 21G 30% / tmpfs 64M 0 64M 0% /dev tmpfs 1.7G 0 1.7G 0% /sys/fs/cgroup shm 64M 0 64M 0% /dev/shm /dev/sda2 30G 9.0G 21G 30% /data
When I stop the container, the volume is still alive:
]# docker volume ls DRIVER VOLUME NAME [...] local mongodb.data
But when I start the container, all databases that were created previously are gone.
So the documentation seems to be wrong somehow, I think.
Is there a better way to save the data with a scp cron job or something similar?