I’m created 3 mongodb containers with a replica set and initiated it and one percona mongo exporter but It is failing with the error
Error msg=“Cannot connect to MongoDB: invalid MongoDB options: a direct connection cannot be made if multiple hosts are specified”
here is the commands used
docker run
–detach
–name mongodb1
-p 30001:27017
mongo
–replSet mongoSet
docker run
–detach
–name mongodb2
-p 30002:27017
mongo
–replSet mongoSet
docker run
–detach
–name mongodb3
-p 30003:27017
mongo
–replSet mongoSet
docker run -d -p 9216:9216 --name mongodb-exporter percona/mongodb_exporter:2.37.0 --mongodb.uri=mongodb://user:pass@172.17.0.3:27017/?replicaSet=mongoSet
here 172.17.0.3 is the container ip address of mongodb1
inside mongoshell of mongodb1:
config = { “_id”:“mongoSet”,“members”:[{_id:0,host:”172.17.0.3:27017"},{_id:1,host:“172.17.0.4:27017”},{_id:2,host:“172.17.0.5:27017”}] };
rs.initiate(config)
rs.status() For this command I see primary is mongodb1 and the rest are secondary in the output