# Mongo exporter not working when used in docker containers

**URL:** <https://forums.percona.com/t/mongo-exporter-not-working-when-used-in-docker-containers/26044>\
**Category:** MongoDB\
**Tags:** closed-no-reply, mongodb-exporter\
**Created:** [October 19, 2023, 1:23pm UTC](https://forums.percona.com/t/mongo-exporter-not-working-when-used-in-docker-containers/26044 "2023-10-19T13:23:25Z")\
**Posts on this page:** 1\
**Page:** 1

<div class="post-metadata">

**Author:** ![Avinash\_sanapala](https://sea1.discourse-cdn.com/flex019/user_avatar/forums.percona.com/avinash_sanapala/32/11499_2.png) [@Avinash\_sanapala](https://forums.percona.com/u/Avinash_sanapala)\
**Post date:** [October 19, 2023, 1:23pm UTC](https://forums.percona.com/t/mongo-exporter-not-working-when-used-in-docker-containers/26044/1 "2023-10-19T13:23:25Z")

</div>

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
