I am currently gradually migrating a docker-less web service to docker. Currently I am struggling with following: The backend code should run in a docker container, but store/retrieve persistent data from a mariadb/mysql database hosted natively on the docker's host machine (Linux). I successfully made a connection from the docker container to the host's sql server using the host.docker.internal (as discussed and solved in From inside of a Docker container, how do I connect to the localhost of the machine? ).
However, for that to work I have to make the SQL server accept remote connections, as the connection out from the docker container seems to not come "via localhost" (I am not network expert enough to phrase it properly). Opening up a SQL server for remote connections is generally not recommended. Is there a way to make the SQL calls from inside the docker container go via the host's localhost address?
Hence, I wonder what are my other options besides
- also dockerizing the sql server (can be done at a later stage, and I am aware this is the more sustainable thing to do, but it requires some more efforts I can't spend right now)
- using the --network="host" setting (doesnt feel right as its giving the container and host much more exposure)
I feel I am missing something here, as my current target setup seems very common (see the cited SO question and the number of votes there).