I try to connet my spring boot app with MySQL Docker Container. I ran :
docker run --name mysql-demo -e MYSQL_ROOT_PASSWORD=password -e MYSQL_DATABASE=test -e MYSQL_USER=sa -e MYSQL_PASSWORD=password -d mysql:lat
and got
CONTAINER ID IMAGE COMMAND CREATED STATUS PORTS NAMES
8d540d1824b9 mysql:latest "docker-entrypoint.sā¦" 23 minutes ago Up 23 minutes 3306/tcp, 33060/tcp mysql-demo
In my spring app I have a property file:
spring.datasource.url=jdbc:mysql://mysql-demo:3306/test
spring.datasource.username=sa
spring.datasource.password=password
spring.jpa.hibernate.ddl-auto=update
spring.datasource.driver-class-name=com.mysql.cj.jdbc.Driver
spring.jpa.properties.hibernate.dialect = org.hibernate.dialect.MySQL5InnoDBDialect
when I try to run this app or build a jar it crash with this error
The last packet sent successfully to the server was 0 milliseconds ago. The driver has not received any packets from the server.
The app working if I use mysql locally without docker