Situation: I have been connecting to a MongoDB through an SSH Tunnel from python scripts that I run locally. I am using SSHTunnelForwarder and PyMongo for this. The scale of the scripts have somehow outgrown what my mac is able to do in a reasonable amount of time, which is why I want to start deploying them to remote servers running in a docker container. I want to test that everything works locally first.
Problem: I am not very experienced with Docker and have not yet found a practicable/understandable solution to tunnel to the MongoDB from inside my Docker container.
I found this extremely helpful post on how connections from inside a docker container should work for a MYSQL db From inside of a Docker container, how do I connect to the localhost of the machine? .
However, unfortunately I don't understand how I would have to set everything up to get it working to access a MongoDB from inside the container through a tunnel.
I presume, that I would have to do the following:
Create a SSH tunnel from my terminal (how?) I am currently using SSHTunnelForwarder from within my python scripts.
Get the IP and Port of the local endpoint of my tunnel (how?)
Run my docker with --net=host host.docker.internal (is that enough? from what I understand host.docker.internal only resolves to my local IP, but how would it know the IP of the endpoint of my tunnel?
How would I then set up my MongoDB client within the Docker container? I am using PyMongo and for setting up the client I need an IP (which would be the remote bind address?) and a port (which would be what?)
Cheers