Adding a local RethinkDB database

Back To Blog

In this tutorial we will add a RethinkDB database in the db/ folder working in an opeNode instance. It is worth noting that it will consume at least 20 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 RethinkDB by adding the following instructions in your Dockerfile:

RUN apk add rethinkdb
RUN echo 'mkdir -p db' >> /usr/bin/start.sh
RUN echo 'rethinkdb --bind all -d db/ --no-update-check &' >> /usr/bin/start.sh

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:

db/

The Complete Dockerfile we used:

FROM node:10-alpine

WORKDIR /opt/app

ENV PORT=80

RUN apk add rethinkdb
RUN echo 'mkdir -p db' >> /usr/bin/start.sh
RUN echo 'rethinkdb --bind all -d db/ --no-update-check &' >> /usr/bin/start.sh

RUN echo 'npm install --production' >> /usr/bin/start.sh

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

We tested it with a simple Node.js TODO application, please see this repository.


Added on Wed Dec 05 2018 01:00:40 GMT+0000 (Coordinated Universal Time)