I got a microsservice and a local mysql database. I´m trying to run my miccroservice from a container but it can´t connect to database
I´ve created this dockerfile
FROM openjdk:14-jdk-alpine
COPY target/docker-forum-0.0.1-SNAPSHOT.jar forum-0.0.1.jar
ENTRYPOINT ["java","-jar","/forum-0.0.1.jar"]
and my properties I tried two different approaches but none worked
spring.datasource.driver-class-name=com.mysql.cj.jdbc.Driver
#spring.datasource.url=jdbc:mysql://localhost/fj27_spring? createDatabaseIfNotExist=true&useSSL=false&allowPublicKeyRetrieval=true&useTimezone=true&serverTiezone=UTC
spring.datasource.url=jdbc:mysql:172.17.0.1:3306/fj27_spring?createDatabaseIfNotExist=true&useSSL=false&allowPublicKeyRetrieval=true&useTimezone=true&serverTimezone=UTC
spring.datasource.username=root
spring.datasource.password=root
From VsCode terminal, I did
docker build --tag=forum:latest .
Then
docker run -p8080:8080 forum:latest
The result was
com.mysql.cj.jdbc.exceptions.CommunicationsException: Communications link failure
The last packet sent successfully to the server was 0 milliseconds ago. The driver has not received any packets from the server.