Docker container host machine communication
You can run your flask container using the host networking mode. This way docker won't isolate the container and will run it the same network namespace as the host, and you container will be able to discover your database using localhost as mongodb hostname
docker run --network host &lt;flask-image&gt;