How to mount external volume for mongoDB using docker-compose and docker-machine

casra picture casra · Dec 21, 2015 · Viewed 31.5k times · Source

I would like to persist the mongoDB data outside of the container and on a specified volume. I am using docker-compose and the yml file looks like

web:
  build: .
  command: python -u app.py
  ports:
    - "5000:5000"
  volumes:
    - .:/todo
  links:
    - db
db:
  image: mongo:3.0.2

Answer

dnephin picture dnephin · Dec 22, 2015

As documented on the docker hub page for that image (https://hub.docker.com/_/mongo/) you can use

volumes:
  - './data:/data/db'

Which will use the host path ./data