0

I have written a very simple demo project, you can download it by clicking here.

The above java project will be containerized as an docker image. But it needs to connect to the local mysql database which is not containerized.

I tried changing the value of spring.datasource.url from jdbc:mysql://localhost:3306/db?characterEncoding=utf8&useSSL=false to jdbc:mysql://192.168.1.105:3306/db?characterEncoding=utf8&useSSL=false in the application.yaml. This change seems to bring success.

so I Change the value of spring.datasource.url back to the original and tried docker run --network=host .....,but this didn't success.. why?

Thanks a lot.

  • Are you running your demo app in linux m/c ? The host networking (`network=host`) only works on Linux hosts, and is not supported on Docker Desktop for Mac, Docker Desktop for Windows, or Docker EE for Windows Server. You can check https://docs.docker.com/network/host/ for details – Sachin May 24 '20 at 13:29
  • @Sachin Thank you very much, it runs in windows.... so is there a method for app in windows? Thanks. – Xavier. Sun May 24 '20 at 13:39
  • cant you use the docker host ip in your properties file ? From the above description you have mentioned it works. you could also try `host.docker.internal` as mentioned in documentation - https://docs.docker.com/docker-for-windows/networking/. you can also refer to similar question in SO - https://stackoverflow.com/questions/52017473/spring-boot-application-in-docker-container-with-mysql-in-host, https://stackoverflow.com/questions/24319662/from-inside-of-a-docker-container-how-do-i-connect-to-the-localhost-of-the-mach – Sachin May 24 '20 at 13:59

0 Answers0