question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

`ServerSelectionTimeoutError` on Dockerized Mongodb Replica Set

See original GitHub issue

I’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:closed
  • Created 8 years ago
  • Reactions:4
  • Comments:11 (4 by maintainers)

github_iconTop GitHub Comments

6reactions
vancouverwillcommented, Oct 19, 2018

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

2reactions
robertaistleitnercommented, Mar 24, 2016

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

  1. the server where mongodb itself is running on, as well as
  2. the server where mongo-connector is running on

because otherwise host name resolution will fail from pymongo library.

This solved the problem for me…

Read more comments on GitHub >

github_iconTop Results From Across the Web

MongoDB Replica Docker: Cannot connect on replica, only ...
With a replicaset it is the config in the replica set that a client will connect to. I prefer to use different ip's...
Read more >
Unable to access mongodb-replicaset with local pymongo client
I have deployed mongodb on Kubernetes using mongodb-operator (verison: 1.9.2). The ReplicaSet consists of 3 instances: 1 primary and 2 ...
Read more >
Cannot connect to MongoDB in docker - Server Fault
You have to tell the container to use it's own IP Address instead of localhost. For example, let's assume you generated scaffold code...
Read more >
MongoDB replica set with one dockerized and two non ...
I'm beginner in the world of docker containers. I want to convert a standalone mongodb running in a docker container to a replica...
Read more >
Dockerizing a MongoDB Replica Set With TLS/SSL
Introduction The goal of this guide is to create a local SSL-enabled MongoDB Replica Set... Tagged with mongodb, docker, security, ...
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found