Search code examples
mongodbdockermeteordocker-compose

Why does my MongoDB data disappear when I convert my Meteor App to use Docker?


I recently switched my meteor app to use Docker as I am trying to create a new microservice. Previously, I would deploy my app locally using meteor run, but I've switched to docker-compose up --build using a docker-compose.yml at the root of my project and a Dockerfile in my Meteor app's directory. I finally got things running, which is great, but all the data I persisted when launching the app via meteor run is not being correctly accessed. I know the data still exists because when I try launching the app with meteor run the data is restored from the previous sessions.

This leads me to believe I am not connecting to Mongo correctly through Docker, and would appreciate any help finding an answer.

FYI, I am connect to a mongo instance it's just a freshly wiped DB.

docker-compose.yml:

version: '3'

services:
  aldoa:
    build:
      context: ./js/app
      dockerfile: Dockerfile
    ports:
      - '3000:3000'
    links:
      - mongo
    environment:
      ROOT_URL: ${APP_ROOT_URL:-http://localhost}
      MONGO_URL: mongodb://mongo:27017/meteor
      PORT: 3000
    volumes:
      - ./opt/app:/./js/app

  mongo:
    image: mongo:latest
    ports:
      - '27017:27017'
    command:
      - --storageEngine=wiredTiger
    volumes:
      - data:/data/db

volumes:
  data:

Thanks in advance!


Solution

  • Then you launch meteor using meteor or meteor run you run in development mode. In that mode, unless you explicitly defined the MONGO_URL environmental variable, meteor will start it's own mongo instance on port 3001 (or, to be precise, the meteor port specified with -p plus one).

    In your docker deployment you are doing the right thing for production and use a separately launched mongo instance running on the default port (27017).

    You can export your data from your development instance by running:

    $ meteor
    $ # in a separate terminal:
    $ mongodump -p 3001 -d meteor
    

    And then import that into the "real" mongo instance:

    mongorestore /path/to/dump/created/above