Adding a local Mongodb database

Back To Blog

In this tutorial we will add a Mongodb database in the db/ folder working in an opeNode instance. It is worth noting that it will consume at least 100 MB extra memory, so if you use for instance the smallest instance plan, it is recommended to increase your plan. Also, we use use an alpine-based docker image. You can enable Mongodb by adding the following instructions in your Dockerfile:

RUN apk add mongodb
RUN echo 'mkdir -p db' >> /
RUN echo 'mongod --dbpath /opt/app/db/ &' >> /

Further, make sure to define a storage area so that it does not get deleted on updates (persistent):

openode add-storage-area db/

And also make sure to ignore that folder by creating an .openodeignore file with:


The Complete Dockerfile we used:

FROM node:10-alpine

WORKDIR /opt/app


RUN apk add mongodb
RUN echo 'mkdir -p db' >> /
RUN echo 'mongod --dbpath /opt/app/db/ &' >> /

RUN echo 'npm install --production' >> /

# npm start, make sure to have a start attribute in "scripts" in package.json
RUN echo 'sleep 3' >> /
CMD sh / && npm start

We tested it with a simple Node.js hello world, please see this repository.

Added on Tue Nov 27 2018 01:37:06 GMT+0000 (Coordinated Universal Time)