2

I have a local MySQL server, that listens to the port 3306 on 127.0.0.1 (not 0.0.0.0!) and though accessible only from my local machine.

I want to run a docker or podman (rootless) container and allow it to connect to my MySQL server.

What I practically trying to do is to pass SSH-Option -L/-R port tunnel option to docker run or podman run, like so

$ docker run ... -L 3306:localhost:3306

or

$ docker run ... -R 3306:localhost:3306

(depending from which point of view you see this tunnel being established)

I tried to use --add-host=host.docker.internal:host-gateway option, but it requires me to make MySQL listen to 0.0.0.0:3306 and I don't want to do it due to security reasons.

  • My question: How can I create a tunnel between my 127.0.0.1:3306 and to some port within the container?
Boris Brodski
  • 8,425
  • 4
  • 40
  • 55
  • If the container and the SQL Server are both running on your local host, then you can `podman run .... --net=host ...` to bind the container to the host's network and then access the SQL Server on host port `3306` using container port `3306` (since they're the same). – DazWilkin Aug 14 '22 at 16:55
  • Related: https://stackoverflow.com/q/24319662/596285 – BMitch Aug 14 '22 at 18:34

0 Answers0