Reputation: 57
I have a mysql which is running on docker container. Using this command to pull and run container
$ docker container run --name cloud --network employee -e MYSQL_ROOT_PASSWORD=root -e MYSQL_DATABASE=bootdb -d mysql:5.7
spring boot application which is at local - i'm trying to establish a connection between java application and mysql container:
Configuration Properties :
spring.datasource.url=jdbc:mysql://cloud/bootdb?serverTimezone=UTC&characterEncoding=UTF-8&useUnicode=true&allowPublicKeyRetrieval=true&useSSL=false
spring.datasource.username=root
spring.datasource.password=root
spring.datasource.platform=mysql
spring.datasource.initialization-mode=always
spring.jpa.hibernate.ddl-auto = create
spring.datasource.driverClassName=com.mysql.jdbc.Driver
spring.jpa.properties.hibernate.dialect = org.hibernate.dialect.MySQLDialect
Error:
although I have done everything to build that application by changing mysql connector version and mysql container version the same. couldn't make it to success. -
pom file configuration -
Upvotes: 0
Views: 705
Reputation: 2467
when you say - Spring Boot app is running on your local - I assume it is running outside of docker.
Try following options
Step1 : Create mysql container again with exposed port : 3306
docker run --name cloud --network employee -p 3306:3306 -e MYSQL_ROOT_PASSWORD=root -e MYSQL_DATABASE=bootdb -d mysql:5.7
Step2 : Verify using that mysql is running on the exposed port and you can access it. Take help from MY-SQL GUI tools.
Step3 : Update spring-boot configuration files.
spring.datasource.url=jdbc:mysql://localhost:3306/bootdb?serverTimezone=UTC&characterEncoding=UTF-8&useUnicode=true&allowPublicKeyRetrieval=true&useSSL=false
Upvotes: 1