Hi i’m trying to communicate with mongodb in the host from a flask container…
So using “docker.host.internal” on the URI didn’t work (host machine is Ubuntu)
Any suggestions ?? To solve this
DevOps Stack Exchange is a question and answer site for software engineers working on automated testing, continuous delivery, service integration and monitoring, and building SDLC infrastructure. It only takes a minute to sign up.Sign up to join this community
From the point of view of your MongoDB instance and your Flask app they're running on separate servers, so the steps to make the former visible to the latter are the same as if they were running on two different physical servers.
Check if the servers are on the same LAN - they are (docker bridge network).
Find if MongoDB is configured to listen on all network interfaces. If not either configure it to do so or to listen on the interface that is connected to the LAN both servers have in common.
If you haven't already, find what IP your MongoDB server has on the common LAN and set Flask app to use it to connect to the database.
Optionally, if your MongoDB server has a firewall, make sure that whatever port MongoDB is listening on is not blocked.
You can add an alias IP address to the loopback interface on the host to get a consistent address to use from your containers.
Any private address you won't see on the local or container networks, something like 10.8.8.8
/etc/network/interfaces.d/lo for a permanent address after reboot
auto lo iface lo inet loopback iface lo inet static address 10.8.8.8/32
or to temporarily test
ip address add 10.8.8.8/32 dev lo