Mort De Rire or MongoDB Docker Replication.
You cannot select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
 
 
 
Ulrich Van Den Hekke 86b6f2c8fa fix(replica): Add information about the replica 5 years ago
extra feat: Create the README file 5 years ago
src fix(replica): Add information about the replica 5 years ago
.dockerignore feat: Create the README file 5 years ago
.drone.yml feat: Create the README file 5 years ago
.gitignore feat: create the first version of MDR 5 years ago
Dockerfile feat: create the first version of MDR 5 years ago
README.md feat: Create the README file 5 years ago
config.yml feat: create the first version of MDR 5 years ago
docker-compose.dev.yml feat: Create the README file 5 years ago
docker-compose.yml feat: Create the README file 5 years ago
mongodb-keyfile feat: create the first version of MDR 5 years ago
package-lock.json feat: Create the README file 5 years ago
package.json feat: Create the README file 5 years ago
tsconfig.json feat: create the first version of MDR 5 years ago
tslint.json feat: create the first version of MDR 5 years ago

README.md

MongoDB Docker Replica-set for Docker Swarm cluster

Build Status

This application is used as a controller for a Mongo DB replica-set deployed on a Docker Swarm cluster. This application is inspired by mongo-rs-controller-swarm but provide the ability to set a user and a password to connect to the replica set, to define an arbitrer or some other options that can be set on a mongodb member.

Officially tested mongo versions:

  • 3.6

Officially tested docker versions:

  • 17.09

Prerequisites

  • Docker-Swarm is installed and already configured.

How to use

You can use the inspiration of the following docker-compose file :

version: '3.4'

networks:
  mongonet:
    driver: overlay

configs:
  mongodb-keyfile:
    file: ./mongodb-keyfile
  controller-config:
    file: ./config.yml

services:
    rs0:
        image:  mongo:3.6
        command: ["mongod", "--replSet", "rs0", "--keyFile", "/mongodb-keyfile"]
        configs:
            - source: mongodb-keyfile
              target: /mongodb-keyfile
              uid: '999'
              gid: '999'
              mode: 0600
        environment:
            - MONGO_INITDB_ROOT_USERNAME=admin
            - MONGO_INITDB_ROOT_PASSWORD=admin
        networks:
            - mongonet
        deploy:
            mode: replicated
            replicas: 3
            restart_policy:
                condition: on-failure
            update_config:
              parallelism: 1
              delay: 1m30s

    controller:
        image: phoenix741/mdr:latest
        configs:
            - source: controller-config
              target: /src/config.yml
        volumes:
            - /var/run/docker.sock:/var/run/docker.sock
        networks:
            - mongonet
        depends_on:
            - rs0
        deploy:
          mode: replicated
          replicas: 1
          placement:
            constraints:
                - node.role == manager
          restart_policy:
            condition: on-failure

You can customize the docker file and launch it with the following command :

  • docker stack deploy -c docker-compose.yml mongodb

This docker compose file will :

  • create a network that will have the name mongodb_mongonet
  • define a config file mongodb-keyfile that will be used by mongodb
  • define a config file controller-config that will be used by the controller
  • create a service of 3 replica mongodb with an admin user
  • create the controller that will initiate and manage the replicaset.

The name of the stack mongodb will be part of the name of the service and of the network so il will be defined in the configuration.

The configuration file used to manage the controller will contains the following informations :

debug: 0

docker:
  # Connection to the docker socket
  connection:
    socketPath: '/var/run/docker.sock'
  # Information about the service (name and network prefixed by the stack name)
  service:
    name: mongodb_rs0
    network: mongodb_mongonet
  # Detection time before the application stop working
  detection: 
    attemps: 10
    timeout: 5000

mongodb:
  # Name of the replicaset
  replicaSet: rs0
  # Port of the replicaset
  port: 27017
  # Connection information (username, password)
  auth:
    username: admin
    password: admin

Then we can define some label on docker container or on node to define some property of the replica set member, for the replica-set with the name rs0, the following label can be defined on the node :

  • MONGODB_rs0_ARBITER_ONLY = true|false
  • MONGODB_rs0_HIDDEN = true|false
  • MONGODB_rs0_PRIORITY = number
  • MONGODB_rs0_SLAVE_DELAY = number
  • MONGODB_rs0_VOTES = 0|1

If a label is modified, only new task on the replica-set will be update with the value of the replica-set.

On production environment, the mongo service should be launch on mode global with a constraint or using the mode replicated but with a placement preferences of type spread.