Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

ServerSelectionTimeoutError on Dockerized Mongodb Replica Set #391

Closed
letsgolesco opened this issue Feb 22, 2016 · 11 comments
Closed

ServerSelectionTimeoutError on Dockerized Mongodb Replica Set #391

letsgolesco opened this issue Feb 22, 2016 · 11 comments

Comments

@letsgolesco
Copy link

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.

@aherlihy
Copy link
Contributor

Hello!

Can you send us the mongo-connector logs? Also any and all information about how you're setting up docker would be useful. Thanks!

@kocuroglu
Copy link

At one installation, I have faced the same situation. As a workaround, connected to mongo (docker exec -it <mongo docker name> mongo), then run these commands:

cfg = rs.conf()
cfg.members[0].host = "localhost:27017"
rs.reconfig(cfg)

I don't know if this has any downside but looks like working.

@aherlihy
Copy link
Contributor

@letsgolesco Hello, has the workaround above solved your issue?

@robertaistleitner
Copy link

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..

@aherlihy aherlihy self-assigned this Apr 25, 2016
@aherlihy
Copy link
Contributor

Thank you for the workarounds! I have added this issue to the FAQ.

@oxymor0n
Copy link
Contributor

@aherlihy just for future reference, this issue is indeed because mongo-connector cannot resolve the hostnames inside admin.system.replset for the MongoDB cluster. I encounter the same issue with my cluster running on Azure VMs, which was configured to use the internal domain names for the VMs instead of the publicly accessible ones. To fix it, change the hostnames to the ones that can be resolved by mongo-connector using this guide: https://docs.mongodb.com/manual/tutorial/change-hostnames-in-a-replica-set/

@impanda-cookie
Copy link

The same issue with docker on mac osx.

Because of mongodb rs.initial() auto assign a random hostname into rs.conf() when i create a default rs mongodb instance.

afdf6a751b18(mongod-3.4.8)[PRIMARY:rs0] admin> rs.conf()
{
  "_id": "rs0",
  "version": 45068,
  "protocolVersion": NumberLong("1"),
  "members": [
    {
      "_id": 0,
      "host": "192.168.99.100:27017", //reset this hostname to docker container ip address 
      "arbiterOnly": false,
      "buildIndexes": true,
      "hidden": false,
      "priority": 1,
      "tags": {

      },
      "slaveDelay": NumberLong("0"),
      "votes": 1
    }
  ],
  "settings": {
    "chainingAllowed": true,
    "heartbeatIntervalMillis": 2000,
    "heartbeatTimeoutSecs": 10,
    "electionTimeoutMillis": 10000,
    "catchUpTimeoutMillis": 60000,
    "getLastErrorModes": {

    },
    "getLastErrorDefaults": {
      "w": 1,
      "wtimeout": 0
    },
    "replicaSetId": ObjectId("59b28470a01cd46654efc5a9")
  }
}

So we can performance rs.reconfig() reset the mongo rs hostname to mongo docker container ip address (in my host default ip address 192.168.99.100 ) it work for me .

@fnordian
Copy link

fnordian commented Dec 4, 2017

I have the same issue. Strangely it ran for a while, but after rebooting and redeploying the swarm cluster, the error occurred. Can this be fixed instead?
In my setup, mongodb is not reachable under a public ip.

@vancouverwill
Copy link

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

@johnfrades
Copy link

@vancouverwill hey man, i just wanna ask where did you get your mongo-connector in docker?

@thearabbit
Copy link

@vancouverwill, when I config rs.initiate() with docker hostnae:internal_port

config = {
  _id: "mongors",
  members: [
    { _id : 0, host : "mongors1:27017" },
    { _id : 1, host : "mongors2:27017" },
    { _id : 2, host : "mongors3:27017" }
  ]
}

I can't connect to mongo replica set

mongo 'mongodb://localhost:2001,localhost:2002......' // external port

Please .....

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests