I have deployed a docker container on a digital ocean droplet (Ubuntu 16.04) that should connect to a JAR on door 9000 and to Mongo on door 27017 in the same machine. Both the services (the JAR and Mongo) are not containers and run on localhost.
I am able to connect to the JAR without problems, but every time I try to connect to mongo I end up in this:
pymongo.errors.ServerSelectionTimeoutError: 178.128.206.98:27017: timed out
This is what I did so far.
The Jar started working when I added the container IP to the ufw
rules:
sudo ufw allow from DOCKER_IP to any port 9000
So I tried the same for mongo:
sudo ufw allow from DOCKER_IP to any port 27017
But once again, I end up in a timeout error. Therefore I followed some guidelines as:
1) drivers issue. Followed by timeout issue I added the srv with dns package, but still did not work.
2) So I followed a networking issue
and I commented out the door from mongod.conf
:
sudo nano /etc/mongod.conf
That now looks like this:
# network interfaces
net:
port: 27017
# bindIp: 127.0.0.1
Of course I have restarted the mongo service
sudo service mongod restart
But still same timeout error.
These are all the variants of python code I have tried reading here and there:
client = MongoClient('mongodb+srv://MACHINE_IP:27017/') #first variant
client = MongoClient(MACHINE_IP, 27017) #second variant
client = MongoClient('mongodb://mongo:27017/') #third variant
Are there any other suggestions on how to connect to mongo? And at the same time, why I am able to connect to the JAR but not to mongo?