Catfish
Catfish

Reputation: 19294

Docker MEAN stack which FROM to use?

I want to create a docker container to load the MEAN stack (Mongo - Node specifically). From my understanding I can't use multiple FROM statements in my Dockerfile, what is the easiest way to setup both Node and Mongo on a docker image?

Do i do this,

FROM node:0.10.40

RUN <whatever the mongo install command is>

or this,

FROM mongo:2.6.11

RUN <whatever the npm install command is>

or something else?

Upvotes: 1

Views: 197

Answers (1)

Charles Duffy
Charles Duffy

Reputation: 295403

Look at the Dockerfiles backing these sources!

If they're both FROM comparable sources (ie. ubuntu), then you should be able to take the mongo dockerfile and modify it to go FROM the node image, thus generating an image with both services available.

Thus, amending the mongo:2.6.11 dockerfile:

FROM node:0.10.40
RUN groupadd -r mongodb && useradd -r -g mongodb mongodb

RUN apt-get update \
    && apt-get install -y --no-install-recommends \
        ca-certificates curl \
        numactl \
    && rm -rf /var/lib/apt/lists/*

# grab gosu for easy step-down from root
RUN gpg --keyserver ha.pool.sks-keyservers.net --recv-keys B42F6819007F00F88E364FD4036A9C25BF357DD4
RUN curl -o /usr/local/bin/gosu -SL "https://github.com/tianon/gosu/releases/download/1.6/gosu-$(dpkg --print-architecture)" \
    && curl -o /usr/local/bin/gosu.asc -SL "https://github.com/tianon/gosu/releases/download/1.6/gosu-$(dpkg --print-architecture).asc" \
    && gpg --verify /usr/local/bin/gosu.asc \
    && rm /usr/local/bin/gosu.asc \
    && chmod +x /usr/local/bin/gosu

RUN gpg --keyserver ha.pool.sks-keyservers.net --recv-keys DFFA3DCF326E302C4787673A01C4E7FAAAB2461C

ENV MONGO_VERSION 2.6.11

RUN curl -SL "https://fastdl.mongodb.org/linux/mongodb-linux-x86_64-$MONGO_VERSION.tgz" -o mongo.tgz \
    && curl -SL "https://fastdl.mongodb.org/linux/mongodb-linux-x86_64-$MONGO_VERSION.tgz.sig" -o mongo.tgz.sig \
    && gpg --verify mongo.tgz.sig \
    && tar -xvf mongo.tgz -C /usr/local --strip-components=1 \
    && rm mongo.tgz*

VOLUME /data/db

COPY docker-entrypoint.sh /entrypoint.sh
ENTRYPOINT ["/entrypoint.sh"]

EXPOSE 27017

...of course, you'll need to amend the entry point to run both services, if you were to do this.


However: Don't do this at all! The best-practices approach is to have multiple containers, one for each service, rather than building only one container that runs all services involved in your stack. Keeping your components each in their own, sandboxed namespace in this way reduces complexity in several respects: There's less room for security breaches to cross containers; there's less interdependence between containers (a software update needed for a new release of node won't break mongodb or the inverse); your containers don't need an init system or other components related to supervising multiple services; etc.

See the Container Linking documentation on the Docker website to understand how to configure your containers to be able to communicate.

Upvotes: 1

Related Questions