From my understanding, docker-compose is a tool that starts multiple containers that will work together on the same machine.
So the way I understand it, your 3 “mongo-rs0-X” containers will be started on the same machine which makes me want to ask a simple question:
Replica Sets are here for one main reason: High Availability in prod. If your 3 nodes depends on some piece of hardware they have in common (same power source, same disk bay, etc), it means you are not really HA because that piece of equipment can fail and bring all your nodes down, all at once. Which is a big NO NO in prod.
That’s the reason why it’s a good practice to deploy your nodes in different data centers.
I also see you are using
--smallfiles which is a deprecated option which was only for MMapV1 which is gone now and
--oplogSize 128 is definitely a terrible idea.
So ─ based on this ─ I think you are trying to deploy a development or test environment here but then I really don’t see the point of deploying 3 nodes on the same cluster. A single node replica set would most probably be good enough, no?
Here is the docker command I use to start an ephemeral single replica set node on my machine when I need to hack something:
docker run --rm -d -p 27017:27017 -h $(hostname) --name mongo mongo:4.4.3 --replSet=test && sleep 4 && docker exec mongo mongo --eval "rs.initiate();"
I actually made an alias out of it which is in my
alias mdb='docker run --rm -d -p 27017:27017 -h $(hostname) --name mongo mongo:4.4.3 --replSet=test && sleep 4 && docker exec mongo mongo --eval "rs.initiate();"'
And ─ because of the
--rm option ─ I can just destroy the container and everything it contains (volumes included) with a simple:
docker stop mongo
Is it what you were looking for or you really need to make these 3 nodes on the same machine work?