Home:ALL Converter>Spring Boot application in Docker Container with MySQL in Host

Spring Boot application in Docker Container with MySQL in Host

Ask Time:2018-08-25T20:48:21         Author:Damien-Amen

Json Formatter

I have a Spring Boot application that I'm planning to run on a Docker container and to test this application I'm connection to MySQL on my host machine. To do that I have a property in my application.properties as below

spring.datasource.url = jdbc:mysql://host.docker.internal:3306/flexapp

Now when I do ./mvnw install dockerfile:build it tried to build the application before building the Docker image. While it's building it says

Caused by: java.net.UnknownHostException: host.docker.internal: nodename nor servname provided, or not known

Obviously it's not able to resolve host.docker.internal.

How do I connect my Spring Boot application in Docker container to the MySql Instance in my host machine? I googled and tried a lot of solution but nothing seems to work.

Author:Damien-Amen,eproduced under the CC 4.0 BY-SA copyright license with a link to the original source and this disclaimer.
Link to original article:https://stackoverflow.com/questions/52017473/spring-boot-application-in-docker-container-with-mysql-in-host
yy