Why is creating a replica set with Docker Compose so complicated?

I am new to MongoDB and have come from PostgreSQL, etc. Usually, deploying an SQL database is straightforward, but with MongoDB, I have never encountered such difficulties.

I started by setting up a standard MongoDB instance, but I couldn’t execute queries because it only works with MongoDB in replSet mode, which is the best practice for production.

So, I tried to set it up and realized how messy it is. I understand that you need to create a script that runs to set up the replica set in addition to executing a command at launch.

Moreover, there are new errors—the authentication method changes and forces me to use authentication keys, but I can’t set them up either because the file permissions are too broad.

After all my struggles, I realized just one thing: the severe lack of functional and standardized documentation on how to properly set up a replica set with Docker Compose.

Is there documentation I missed, or am I not the only one to find this so hard to set up?

It is not. It is simply lack of experience. As you mentioned yourself

but experienced with

If you could be more explicit with the exact issues you have we might be able to help. Going from a standard instance to a single node replica set is usually as easy as https://www.mongodb.com/docs/manual/tutorial/convert-standalone-to-replica-set/.

In the meantime you could use a free M0 to get you going.

9 months later

Not quite sure if this is true. I’ve yet to see a simple three-node docker compose file anywhere that has auth.

Most require you to add entries to the host’s hosts file, restart containers, run scripts etc. Should just be “here are the other containers exposed ports, here’s the keyfile” and then you can just connect with compass.

Not sure why such a simple setup has to be so fragile and complex.