I am running a MongoDB instance inside a Docker container using docker-compose. My data is getting deleted once a day, even though I am using named volumes.
Here is my docker-compose.yml
file:
version: '3.8'
services:
...
statistics_mongo:
image: mongo:latest
restart: unless-stopped
ports:
- '27017:27017'
volumes:
- mongo_production_stats:/data/db
volumes:
mongo_production_stats: {}
...
I never encountered this issue on my local machine, but it happens in production (Ubuntu server).
What I have checked so far:
- The volume is correctly created:
docker volume inspect mongo_production_stats
Shows the correct mount point:
/var/lib/docker/volumes/mongo_production_stats/_data
- The container is running and using the correct volume.
- There are no manual deletions or explicit docker volume rm commands being run.
- Running
docker compose logs statistics_mongo
does not show any database corruption or crashes. - Test data disappears daily, even when the container is not restarted.
- Searched for similar questions but could not find any solution.
My Questions:
- What could be causing this unexpected data loss once a day?
- How can I prevent Docker from losing MongoDB data?
- Are there any system logs or tools I can check to identify if Docker is deleting my volume?
Any insights or debugging steps would be greatly appreciated!