0

I have a " dockerized " springboot app which needs mysql to run.

I've mysql installed on my ubuntu and want to start a container of my app using docker and need to know what to specify in database url connection so that my app connect to the mysql installed on my ubuntu.

something like this jdbc:mysql://locahost:3066/database_name won't work since localhost refers to the container itself which doesn't have mysql instance.

another solution is to start a mysql docker container and specify its name in place of localhost... but i don't want to start a mysql docker container since i already have mysql installed (and would need volume config to keep data persisted)

Thanks in advance.

Mssm
  • 581
  • 4
  • 21
  • 1
    check [this](https://stackoverflow.com/questions/31324981/how-to-access-host-port-from-docker-container) – michalk Aug 18 '19 at 17:26

1 Answers1

1

You need to map the IP of your host to a name inside your container. You do that with

docker run --add-host mysqlhost:192.168.0.3 ...

You need to provide the IP of your host instead of 192.168.0.3

Then your connection string would be: jdbc:mysql://mysqlhost:3066/database_name

Mihai
  • 5,259
  • 1
  • 7
  • 26