I have a Spring boot app that makes jdbc connections to a data base in a different VPC. From my local I don't have access to this data base, so when I deploy my app locally I have to open a ssh tunnel in order to connect to the data base. This is how the tunnel is being set:
ssh -L 61616:data_base_host:data_base_port myuser@tunnel_server
And then my app connects using:
jdbc:sqlserver://localhost:61616....
Now I need to put my app inside a Docker container. This is how I run my docker image:
docker run -p 9018:9018 myapp
9018 is the http port. When the spring boot app starts inside Docker it can't connect to the data base. The error is:
Failed to initialize pool: The TCP/IP connection to the host localhost, port 61616 has failed.
So I need to bind the port 61616 inside the container to the port 61616 in the host. I was able to fix my problem using this jdbc URL:
jdbc:sqlserver://docker.for.mac.localhost:61616
Using the alias docker.for.mac.localhost makes the trick but it is a solution oriented to Mac platforms. I also tried:
docker run -p 9018:9018 -p 61616:61616 myapp
And didn't work.
Any ideas?