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.

  • Install redmine plug-in using docker container
  • Why does uWSGI fail to start in Docker?
  • Build Docker image on different host OS
  • How to Use Docker (or alternative) as Test Environment
  • Accessing docker container from iOS Simulator
  • How to find out about docker image updates via commandline
  • 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?

  • Why php development server hangs with docker compose?
  • apt-get install in Ubuntu 16.04 docker image: '/etc/resolv.conf': Device or resource busy
  • Why is docker looking in /simple for python packages?
  • Interactive command in Dockerfile
  • Problems creating OpenShift app using Dockerfile (with oc new-app)
  • Nexus 3: “Remote Connection Pending…” for docker hub
  • 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).

    Docker will be the best open platform for developers and sysadmins to build, ship, and run distributed applications.