Sign inSign up

imagames/mongodb-replicaset-startup

By imagames

•Updated over 7 years ago

Oneshot container to connect to a mongo replica set and start it

Image
0

1.3K

imagames/mongodb-replicaset-startup repository overview

⁠docker-mongo-replicaset

Docker image for MongoDB Replica Set

⁠Getting started

You can deploy this with a stack file like this:

version: '3.1'

services:
  mongo1:
    image: mongo
    hostname: mongo1
    networks:
      - mongo_replicas
    deploy:
      placement:
        constraints:
          - node.labels.mongo.replica==1
    command: mongod --replSet ${REPL_SET_NAME}

  mongo2:
    image: mongo
    hostname: mongo2
    networks:
      - mongo_replicas
    deploy:
      placement:
        constraints:
          - node.labels.mongo.replica==2
    command: mongod --replSet ${REPL_SET_NAME}
  
  mongo_setup:
    image: imagames/mongodb-replicaset-startup
    deploy:
      restart_policy:
        condition: on-failure
        delay: 5s
    depends_on:
      - mongo1
      - mongo2
    networks:
      - mongo_replicas
    environment:
      REPLICA_SET_ID: ${REPL_SET_NAME}
      PRIMARY_MEMBER: mongo1:27017
      SECONDARY_MEMBERS: mongo2:27017

networks:
  mongo_replicas:
    driver: overlay

You may also set all three of PRIMARY_USER, PRIMARY_PASS and PRIMARY_DB variables if authentication is needed to connect to the primary.

⁠Setup image

The Dockerfile in mongo-replicaset-setup is for initiating the Replica Set on the nodes before stopping.

Tag summary

Content type

Image

Digest

Size

51.8 MB

Last updated

over 7 years ago

docker pull imagames/mongodb-replicaset-startup