Replica set in docker-compose

I’m trying to create a mongodb replica set in docker / docker-compose.

In all the tutorials I’ve found online, the replica set is created in a basic fashion in docker-compose and then an administrator manually initializes the replica set in a mongo shell session.

I’m trying to do something a little better. On startup, the container downloads the latest back from S3, and then initializes or joins a replica set, automatically finding the other containers in the network, according to pattern of numbered hostnames, eg mongo-1, mongo-2, … mongo-9.

I’ve created a starter project here, https://github.com/bboyle1234/MongoSet, and I’m looking for someone who can help complete it. Pay is offered. You will need to be experienced in the following: docker, docker-compose, mongodb, mongodb replication, shell scripting, and s3.

Thank you.

1 Like

I’ve changed direction. Since I’m not able to delete this post, I’ll update y’all with my decision here.

I wanted mongo containers that would not have volumes mapped to the host. So they could appear and disappear anywhere on any server. I envisioned that upon startup, they would restore the latest backup version from S3, and then join an existing replica set to receive the latest updates. I also envisioned that if they could find the other db instances in the replica set, but none of them had the replica set initialised, then it would initialise the replica set.

All that became “too hard” for me, in the sense it would take too long to setup starting from my limited knowledge. Why should I spend another week or two of my time setting this up so that once or twice a year, some administrator in my company doesn’t have to type “rs.initiate(config)” into a mongo shell? I could spend a few hours on documentation and not a week on learning something with little value to the company. So I did.

We have a backup container dumping backups into S3 every half-hour, and it has the ability to restore any backup version to the mongo cluster. I could not find a container in docker hub that would do backup, restore, AND connect to a replica set, so I rolled my own.

In the event that all three mongo db instances are removed at the same time from the “dynamic” container orchestration, we’re going to have to manually initialise the replicaset and run the restore. O well.