Skip to content
This repository has been archived by the owner on Mar 9, 2018. It is now read-only.

Running with Docker

Reza Akhavan edited this page Sep 15, 2016 · 3 revisions

You can Dockerize your app with just a few changes.

Step 1

Create a Dockerfile in the root directory:

FROM node
RUN mkdir -p /usr/src/app
WORKDIR /usr/src/app
COPY package.json /usr/src/app/
RUN npm install
COPY . /usr/src/app
EXPOSE 8000
CMD [ "npm", "start" ]

Step 2

Create a docker-compose.yml in the root directory:

version: '2'
services:
  app:
    build: .
    ports:
      - "8000:8000"
    environment:
      - MONGODB_URI_DEFAULT=mongodb://db:27017/aqua
    links:
      - db
  db:
    image: mongo
    ports:
      - "27017:27017"

Step 3

Change config.js to accept the MongoDB URI via environment variables in all cases:

            uri: {
                 $filter: 'env',
                 production: process.env.MONGODB_URI,
-                test: 'mongodb://localhost:27017/aqua-test',
-                $default: 'mongodb://localhost:27017/aqua'
+                test: process.env.MONGODB_URI_TEST,
+                $default: process.env.MONGODB_URI_DEFAULT
             }
         },
         autoIndex: true

Run it

Now to run the app simply:

$ docker-compose up

That's it

We hope this was helpful. If you have questions or think this page should be expanded please contribute by opening an issue or updating this page.

Special thanks to @madnight for sharing this.