1

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).

jbreu
  • 11
  • 1
  • Check this out - https://stackoverflow.com/a/44544841/2777988 – Rakesh Gupta Jan 09 '22 at 16:34
  • ”Also, check that your MySQL is listening to all of its interfaces. In your my.cnf search for bind-address that should be 0.0.0.0 (consider security issues if your server has public IP).“ That‘s exactly what I can’t do and why your linked solution doesn’t work for me. Thanks nevertheless! – jbreu Jan 09 '22 at 18:46
  • Does this answer your question? [From inside of a Docker container, how do I connect to the localhost of the machine?](https://stackoverflow.com/questions/24319662/from-inside-of-a-docker-container-how-do-i-connect-to-the-localhost-of-the-mach) – pringi Jan 11 '22 at 09:57
  • Nope, thats the one linked in the OP. Using the host.docker.internal doesnt go as localhost, and the --network=host solution works but is a sledgehammer approach (see OP). – jbreu Jan 12 '22 at 10:22

0 Answers0