`ServerSelectionTimeoutError` on Dockerized Mongodb Replica Set
See original GitHub issueI’m trying to use Docker locally to test out mongo-connector but with no luck so far.
It works fine when connecting to a local mongod instance (i.e. just running mongod --replSet singleNodeRepl
in terminal), but in Docker I get this error:
ServerSelectionTimeoutError: Could not reach any servers in [(u'344da2f17060', 27017)]. Replica set is configured with internal hostnames or IPs?
For some reason, the IP address of the replica set member inside the Docker container is a hex string: 344da2f17060
.
Any way to make this work in Docker?
Following the instructions here, I created a replica set in a docker container (i.e. docker run mongo mongod --replSet singleNodeRepl
), executed rs.initiate()
from its mongo shell, loaded it up with some data and ran mongo-connector like so:
mongo-connector -c mongo-connector-config.json -m 192.168.99.100:27017 -t 192.168.99.100:9200 -d elastic_doc_manager
The config only contains namespaces.
Issue Analytics
- State:
- Created 8 years ago
- Reactions:4
- Comments:11 (4 by maintainers)
to get this to work on mac (osx has weird config with docker) with locally hosted mongo and mongo-connector in docker we had to add to our mac’s hosts file
127.0.0.1 host.docker.internal
Then we updated replica set as stated above so
cfg.members[0].host = "host.docker.internal:27017"
This worked good for us
I have the same issue, also using docker containers. The fix with localhost:27017 doesn’t solve the problem for me, because mongo-connector is running in a different container and hast no idea where localhost:27017 is…
I think the only solution is to use host names which can be resolved by
because otherwise host name resolution will fail from pymongo library.
This solved the problem for me…