Public Repository

Last pushed: a year ago
Short Description
Dev MongoDB with replica set configuration, running on ports 27017, 27018 and 27019
Full Description

How to use this image

MAKE SURE YOUR LOCAL MONGO DB IS NOT RUNNING ON PORT 27017

start mongo instances:

docker run --name appd1-mongo -p 27017:27017 -p 27018:27018 -p 27019:27019 -d appd1/mongodev

This image will configure the replicaset with the ip address 10.0.75.2 runing on host docker.local

DOCKERFILE

FROM debian:wheezy

RUN groupadd -r mongodb && useradd -r -g mongodb mongodb

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

# grab gosu for easy step-down from root
ENV GOSU_VERSION 1.7
RUN set -x \
    && apt-get update && apt-get install -y --no-install-recommends ca-certificates wget && rm -rf /var/lib/apt/lists/* \
    && wget -O /usr/local/bin/gosu "https://github.com/tianon/gosu/releases/download/$GOSU_VERSION/gosu-$(dpkg --print-architecture)" \
    && wget -O /usr/local/bin/gosu.asc "https://github.com/tianon/gosu/releases/download/$GOSU_VERSION/gosu-$(dpkg --print-architecture).asc" \
    && export GNUPGHOME="$(mktemp -d)" \
    && gpg --keyserver ha.pool.sks-keyservers.net --recv-keys B42F6819007F00F88E364FD4036A9C25BF357DD4 \
    && gpg --batch --verify /usr/local/bin/gosu.asc /usr/local/bin/gosu \
    && rm -r "$GNUPGHOME" /usr/local/bin/gosu.asc \
    && chmod +x /usr/local/bin/gosu \
    && gosu nobody true \
    && apt-get purge -y --auto-remove ca-certificates wget


ENV GPG_KEYS \
    DFFA3DCF326E302C4787673A01C4E7FAAAB2461C \
    42F3E95A2C4F08279C4960ADD68FA50FEA312927
RUN set -ex \
    && for key in $GPG_KEYS; do \
        apt-key adv --keyserver ha.pool.sks-keyservers.net --recv-keys "$key"; \
    done

ENV MONGO_MAJOR 3.2
ENV MONGO_VERSION 3.2.7

RUN echo "deb http://repo.mongodb.org/apt/debian wheezy/mongodb-org/$MONGO_MAJOR main" > /etc/apt/sources.list.d/mongodb-org.list

RUN set -x \
    && apt-get update \
    && apt-get install -y \
        mongodb-org=$MONGO_VERSION \
        mongodb-org-server=$MONGO_VERSION \
        mongodb-org-shell=$MONGO_VERSION \
        mongodb-org-mongos=$MONGO_VERSION \
        mongodb-org-tools=$MONGO_VERSION \
    && rm -rf /var/lib/apt/lists/* \
    && rm -rf /var/lib/mongodb \
    && mv /etc/mongod.conf /etc/mongod.conf.orig

RUN mkdir -p /data/db1 /data/db2 /data/db3 /data/configdb \
    && chown -R mongodb:mongodb /data/db1 /data/db2 /data/db3 /data/configdb

VOLUME ["/data/db1", "/data/db2", "/data/db3", "/data/configdb"]

WORKDIR /

EXPOSE 27017
EXPOSE 27018
EXPOSE 27019

COPY config/mongod_1.conf /conf/mongod_1.conf
COPY config/mongod_2.conf /conf/mongod_2.conf
COPY config/mongod_3.conf /conf/mongod_3.conf
COPY config/start.sh /conf/start.sh

RUN chmod 755 /conf/start.sh

CMD ["/conf/start.sh"]

start.sh

#!/bin/bash

echo "10.0.75.2      docker.local" >> /etc/hosts

hname=$(hostname)

mongod --config /conf/mongod_1.conf --port 27017 --replSet "rs0" --dbpath "/data/db1" --verbose
mongod --config /conf/mongod_2.conf --port 27018 --replSet "rs0" --dbpath "/data/db2" --verbose
mongod --config /conf/mongod_3.conf --port 27019 --replSet "rs0" --dbpath "/data/db3" --verbose

sleep 5 

rsConfig="{  \"_id\" : \"rs0\",  \"version\" : 1,  \"protocolVersion\" : 1,  \"members\" : [ { \"_id\" : 0,  \"host\" : \"docker.local:27017\",  \"arbiterOnly\" : false,  \"buildIndexes\" : true,  \"hidden\" : false,  \"priority\" : 1,  \"tags\" : {  },  \"slaveDelay\" : 0,  \"votes\" : 1 },  { \"_id\" : 1,  \"host\" : \"docker.local:27019\",  \"arbiterOnly\" : true,  \"buildIndexes\" : true,  \"hidden\" : false,  \"priority\" : 1,  \"tags\" : {  },  \"slaveDelay\" : 0,  \"votes\" : 1 },  { \"_id\" : 2,  \"host\" : \"docker.local:27018\",  \"arbiterOnly\" : false,  \"buildIndexes\" : true,  \"hidden\" : false,  \"priority\" : 1,  \"tags\" : {  },  \"slaveDelay\" : 0,  \"votes\" : 1 } ] }"

mongo --host docker.local --port 27017 --authenticationDatabase local --eval "rs.initiate($rsConfig)" local

tail -f /var/log/mongodb/mongodb-db-001.log
Docker Pull Command
Owner
appd1

Comments (0)