I am running Mongo db in a container and trying to set it up as the first node of a replica set. I using the following script to setup the replica set node
rs.initiate({ _id: "rs1", version: 1, members: [ { _id: 0, host: 'container-host-dns:15017' }]})
The container-host-dns
as the name says, is the dns of the container host. And Mongo db’s default port is mapped out to external port 15017
. When I run the above command to initiate the replica set, I am getting the following error:
MongoServerError[InvalidReplicaSetConfig]: No host described in new configuration with {version: 1, term: 0} for replica set rs1 maps to this node
But I can successfully connect to the same Mongo DB (which is running as a standalone instance, since the replica set initiate fails), using the same host and port for the connection string "mongodb://admin:xxxxxx@container-host-dns:15017/?authSource=admin"
. I am not sure why I can connect but somehow mongo db itself could not.
Any idea why this could be happening?
P.S1: Ofcourse, I’ll be adding additional nodes for replica set to work correctly. And even if I list those extra nodes in the rs.initiate command, I am getting the same error. I have removed them from my question for simplicity.
P.S2: If I use the ip insteadof container-host-dns
in the rs.initiate command, then it succeeds. We don’t want to use ip in the replica set cluster config as then the config will need to be updated if or when the ip changes….