Search code examples
mongodbamazon-web-servicesjenkinsdocker-swarm

Unable to connect to MongoDb while I running a job from Jenkins on docker


I have a docker installed on Linux machine, I have a container with Jenkins that trigger a job, my final step is to run tests, one of my first steps in my Nunit tests is to connect to MongoDB that also a part of my docker stack.

From the Jenkins log I got the following error :

A timeout occured after 30000ms selecting a server using
 CompositeServerSelector{ Selectors =
 MongoDB.Driver.MongoClient+AreSessionsSupportedServerSelector,
LatencyLimitingServerSelector{ AllowedLatencyRange = 00:00:00.0150000
 } }. Client view of cluster state is { ClusterId : "1", ConnectionMode
 : "Automatic", Type : "Unknown", State : "Disconnected", Servers : [{
 ServerId: "{ ClusterId : 1, EndPoint : "Unspecified/"my AWS
 host":27017

Please note:

1) MongoDB and Jenkins containers are located on the same network.

2) I can get a curl from Jenkins container to Mongo's full IP address.

3) If I am running from my local pc and pointing to the remote machine (to the same docker) Mongo connection is working.

4) In my AWS console, all traffic and ports are open on both sides.


Solution

  • Had a very similar issue, In my case, we used public DNS that cause us the problem.Consider changing from public DNS to Public IP.

    enter image description here