最新消息:雨落星辰是一个专注网站SEO优化、网站SEO诊断、搜索引擎研究、网络营销推广、网站策划运营及站长类的自媒体原创博客

MongoDB Data Loss in Docker Container Once a Day - Stack Overflow

programmeradmin5浏览0评论

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:

  1. The volume is correctly created:
    docker volume inspect mongo_production_stats
    Shows the correct mount point:
    /var/lib/docker/volumes/mongo_production_stats/_data
  2. The container is running and using the correct volume.
  3. There are no manual deletions or explicit docker volume rm commands being run.
  4. Running docker compose logs statistics_mongo does not show any database corruption or crashes.
  5. Test data disappears daily, even when the container is not restarted.
  6. Searched for similar questions but could not find any solution.

My Questions:

  1. What could be causing this unexpected data loss once a day?
  2. How can I prevent Docker from losing MongoDB data?
  3. 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!

发布评论

评论列表(0)

  1. 暂无评论