Docker-compose ReplicaSets - getaddrinfo ENOTFOUND

As title suggests, I am using docker-compose running 3 mongo containers. I have attached the rs.status() log and also a screenshot of Studio3t to scan my ports for the members.


I tried many variations of the connections string and ports based on the mongo documentation. I am new at this and still learning so any info helps!

Hi @TheAdrianReza_N_A and welcome in the MongoDB Community :muscle: !

Have you set your IP addresses correctly in your bindIp network configuration? Did you include in there the IP address of your client in your 3 config files?

If that’s not it, could you please share your config file and your docker-compose.yml maybe so we have a bit more information to work with?

Also ─ just to confirm ─ “mongo-rs0-1”, “mongo-rs0-2” and “mongo-rs0-3” are 3 different physical servers, correct?

Cheers,
Maxime.

I do not believe I have done much in the network configuration. Feel free to suggest ways I can improve my docker-compose.yml file! It’s a boilerplate mongo-rs docker container I found.

And yes they are on 3 different servers.

mongo.conf -

replication:
oplogSizeMB: 1024
replSetName: rs0

Really appreciate the quick response! Let me know if there is anything else I can get you to help my situation!

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 ~/.bash_aliases file:

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?

Cheers,
Maxime.