Mongodb replica set with Docker 1.12 services
Asked Answered
W

1

6

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.

Winsor answered 21/8, 2016 at 0:55 Comment(0)
W
2

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.

Winsor answered 8/1, 2017 at 0:46 Comment(1)
Note that this puts the burden on the application side for failing over to another server. Not very docker-like.Stefanysteffane

© 2022 - 2024 — McMap. All rights reserved.