title: Saving mongodb on volume using docker-compose
body: <p>In my project I have few container managed by docker-compose. I would like to store data from mongoDB on persistent volume. MongoDB seems to store data in /data/db but files are not transferred to my host file system and they disappear after rebuilding container. </p>
  
  <p>Here is my docker-compose config file: </p>
  
  <pre>
  version: '2'
  
  services:
  
    db:
      image: mongo:latest
      volumes: 
        - "db-data:/data/db"
      ports:
        - "27017:27017"
      networks:
        - elk
  
    web: 
      build: ./app
      environment:
        - WAIT_COMMAND=1
      ports:
        - "3000:3000"
      networks:
        - elk
      depends_on: 
        - db
  
  
  networks:
    elk:
      driver: bridge
  
  volumes:
    db-data:
  
  </pre>