Docker with Atlas DB

I am trying to get a meteor app I have to run in a docker image.

I am using the docker image from this GitHub repo:

Here is a copy of my docker-compose.yaml file:

services:
  app:
    build:
      context: .
      dockerfile: Dockerfile
    ports:
      - '3010:3010'
    environment:
      ROOT_URL: ${APP_ROOT_URL:-http://localhost}
      MONGO_URL: mongodb+srv://<user>:<pass>@<atlas cluster>/meteor?retryWrites=true&w=majority
      MONGO_OPLOG_URL: mongodb+srv://<user>:<pass>@<atlas cluster>/local?retryWrites=true&w=majority
      PORT: 3010

and the Dockerfile:

# The tag here should match the Meteor version of your app, per .meteor/release
FROM geoffreybooth/meteor-base:2.15

# Copy app package.json and package-lock.json into container
COPY ./package*.json $APP_SOURCE_FOLDER/

RUN bash $SCRIPTS_FOLDER/build-app-npm-dependencies.sh

# Copy app source into container
COPY ./ $APP_SOURCE_FOLDER/

RUN bash $SCRIPTS_FOLDER/build-meteor-bundle.sh


# Use the specific version of Node expected by your Meteor release, per https://docs.meteor.com/changelog.html; this is expected for Meteor 3.1.2
FROM node:14.21.3-alpine

ENV APP_BUNDLE_FOLDER=/opt/bundle
ENV SCRIPTS_FOLDER=/docker

# Runtime dependencies; if your dependencies need compilation (native modules such as bcrypt) or you are using Meteor <1.8.1, use app-with-native-dependencies.dockerfile instead
RUN apk --no-cache add \
		bash \
		ca-certificates

# Copy in entrypoint
COPY --from=0 $SCRIPTS_FOLDER $SCRIPTS_FOLDER/

# Copy in app bundle
COPY --from=0 $APP_BUNDLE_FOLDER/bundle $APP_BUNDLE_FOLDER/bundle/

RUN bash $SCRIPTS_FOLDER/build-meteor-npm-dependencies.sh

###### Copy Settings File(s) to Meteor Runtime Image
RUN mkdir -p /opt/settings
COPY ./settings.json /opt/settings.json
##### Copy Startup Script to Configure Pre-Runtime Dependencies
COPY ./startup.sh $SCRIPTS_FOLDER/

# Start app
ENTRYPOINT ["/docker/entrypoint.sh"]

CMD ["node", "main.js"]

I am starting the container using the following command:
docker compose up --build --remove-orphans

the --build and --remove-orphans are only while testing.

The problem I am having is that no matter what I do the Meteor App will not use the Atlas DB provided in MONGO_URL:. It always creates a local mongo instance.

What am I doing wrong here?

Thanks.

Hi @genappdevops ,

The MONGO_URL variable must be passed within the METEOR_SETTINGS environment variable. I believe this is the problem.

Here is an example:

services:
  app:
    build:
      context: .
      dockerfile: Dockerfile
    ports:
      - '3010:3010'
    environment:
      ROOT_URL: ${APP_ROOT_URL:-http://localhost}
      METEOR_SETTINGS: '{
        "public": {},
        "private": {
          "MONGO_URL": "mongodb+srv://<user>:<pass>@<atlas cluster>/meteor?retryWrites=true&w=majority",
          "MONGO_OPLOG_URL": "mongodb+srv://<user>:<pass>@<atlas cluster>/local?retryWrites=true&w=majority"
        }
      }'
      PORT: 3010

Best Regards,

1 Like

Thanks for your response @philippeoliveira , that did not solve the issue however. I think the issue might be specific to the docker container I am trying to use.

As per the code here:

It seems like the container is expecting the MONGO_URL: to be set (which it is) but it continues to connect to the local mongo instance.

Is there anyway I can over-ride this in the Meteor.startup?

Thanks