I am using
docker-compose to create a MongoDB service. Here is how it looks:
services: database: image: 'mongo' environment: - MONGO_DATA_DIR=/data/db - MONGO_INITDB_DATABASE=azunyan volumes: - ./container-scripts/mongo-init.js:/docker-entrypoint-initdb.d/mongo-init.js - ./data/db:/data/db
I build and run the service using
sudo docker-compose up --build -d database and this creates the MongoDB container.
During testing I add a few collections to the database by connecting to the database through
mongo <container ip address> and issuing a few mongo commands (e.g.
Afterwards, I use
sudo docker-compose down -v to remove the container, and I also run
sudo docker system prune -a -f just to be sure. I expect that the next time I build and run the image, the database should be empty (i.e. have no collections), however I can see the collections are still there. Why? How do I get a clean MongoDB container?