Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Mongodb replica set with Docker 1.12 services

Im wondering as to how to start a mongodb replica set using the new Docker 1.12 swarm mode service model. starting a service allows you to specify a number of container replicas, which in the minimal replica set case would be 3. but how would then parameters be specified for the replica set primary, if Docker runs individual containers itself, all with the same name of the service (for contacting the containers over the overlay network)?

how would the replica-set containers be contacting each other with different names? mongodb1,mongodb2,mongodb3 - these would have to be different services?

it was all so straight forward with running dockers 'run' command directly... now it seems a little more confusing for state-full containers (replica set members), as oppose to stateless containers, where all containers of a service are the same...

any pointers or links will be helpful.

like image 542
deepblue Avatar asked Aug 21 '16 00:08

deepblue


1 Answers

I realized, via official mongodb guides for a replica set on top of Kubernetes, that you have to declare a new service per replica-set member.

So for a basic replica-set you declare 3 services, one primary, two secondaries - service__primary, service__secondary_1, service_secondary_2.

Each of these swarm services is then only proxying/load-balancing to a single container, that is running the mongod process.

like image 128
deepblue Avatar answered Oct 16 '22 17:10

deepblue