Avoid persisting mongo data in docker-compose
I’m using docker compose to run tests for my application. The configuration looks like:
version: '2' services: web: build: . image: myapp:web ports: - "3000:3000" depends_on: - mongo links: - mongo mongo: image: mongo:3.2.6
Right now, when I run
docker-compose up, there is a volume created automatically (by
docker-compose or the
mongo image?) which maps the Mongo storage data to path like: /var/lib/docker/volumes/c297a1c91728cb225a13d6dc1e37621f966067c1503511545d0110025479ea65/_data.
Since I am running tests rather than production code, I’d actually like to avoid this persistence (the mongo data should go away when the docker-compose exits) — is this possible? If so, what’s the best way to do it?
One Solution collect form web for “Avoid persisting mongo data in docker-compose”
After the containers exit (or you stop them with a down command), clean up the old containers and volumes with
docker-compose rm -v
The -v tells it to also remove the volumes (container volumes and named volumes created with docker-compose, but not host volumes).