I am trying to create docker containers and I was trying to 1 for MySql and another for Spring io. The DB container is running OK but the spring boot container comes at a point and exits. I have searched and tried many thing but I can’t seem to be able to solve it, the thing that I concluded that it seems that something is wrong with the database environment or aplication.properties or maybe it could be somewhere else. I would be so grateful if someone could guide me to the solution.
application.properties:
spring.datasource.url=jdbc:mysql://DB_containerfile:3306/phase2?useSSL=false&allowPublicKeyRetrieval=true&serverTimezone=UTC
spring.datasource.username=testuser
spring.datasource.password= testuser@123
spring.jpa.hibernate.ddl-auto=update
spring.datasource.driver-class-name= com.mysql.cj.jdbc.Driver
dockerfile:
FROM openjdk:17
ADD target/springboot-crud-api-0.0.1-SNAPSHOT.jar app.jar
ENTRYPOINT ["java","-jar","app.jar"]
docker-compose.yml:
version: '3.8'
services:
DB_containerfile:
image: mysql:latest
container_name: DB_containerfile
environment:
- MYSQL_ROOT_PASSWORD=////////////
- MYSQL_DATABASE=phase2
- MYSQL_USER=testuser
- MYSQL_PASSWORD=testuser@123
backend_containerfile:
image: backend_image
container_name: backend_containerfile
ports:
- 8080:8080
build:
context: ./
dockerfile: Dockerfile
depends_on:
- DB_containerfile
NOTE: I assigned the password that I enter when I write this command on the cmd "mysql -u root -p" to MYSQL_ROOT_PASSWORD
Spring boot log:
backend_containerfile | 2022-12-02 06:02:54.757 WARN 1 --- [ main] com.zaxxer.hikari.util.DriverDataSource : Registered driver with driverClassName=com.mysql.jdbc.Driver was not found, trying direct instantiation.
backend_containerfile | 2022-12-02 06:02:56.040 ERROR 1 --- [ main] com.zaxxer.hikari.pool.HikariPool : HikariPool-1 - Exception during pool initialization.
backend_containerfile |
backend_containerfile | java.sql.SQLNonTransientConnectionException: Public Key Retrieval is not allowed
backend_containerfile | at com.mysql.cj.jdbc.exceptions.SQLError.createSQLException(SQLError.java:110) ~[mysql-connector-j-8.0.31.jar!/:8.0.31]
backend_containerfile | at com.mysql.cj.jdbc.exceptions.SQLExceptionsMapping.translateException(SQLExceptionsMapping.java:122) ~[mysql-connector-j-8.0.31.jar!/:8.0.31]
backend_containerfile | at com.mysql.cj.jdbc.ConnectionImpl.createNewIO(ConnectionImpl.java:828) ~[mysql-connector-j-8.0.31.jar!/:8.0.31]
backend_containerfile | at com.mysql.cj.jdbc.ConnectionImpl.<init>(ConnectionImpl.java:448) ~[mysql-connector-j-8.0.31.jar!/:8.0.31]
backend_containerfile | at com.mysql.cj.jdbc.ConnectionImpl.getInstance(ConnectionImpl.java:241) ~[mysql-connector-j-8.0.31.jar!/:8.0.31]
backend_containerfile | at com.mysql.cj.jdbc.NonRegisteringDriver.connect(NonRegisteringDriver.java:198) ~[mysql-connector-j-8.0.31.jar!/:8.0.31]backend_containerfile | at com.zaxxer.hikari.util.DriverDataSource.getConnection(DriverDataSource.java:138) ~[HikariCP-4.0.3.jar!/:na]
backend_containerfile | at com.zaxxer.hikari.pool.PoolBase.newConnection(PoolBase.java:364) ~[HikariCP-4.0.3.jar!/:na]
backend_containerfile | at com.zaxxer.hikari.pool.PoolBase.newPoolEntry(PoolBase.java:206) ~[HikariCP-4.0.3.jar!/:na]
backend_containerfile | at com.zaxxer.hikari.pool.HikariPool.createPoolEntry(HikariPool.java:476) ~[HikariCP-4.0.3.jar!/:na]
backend_containerfile | at com.zaxxer.hikari.pool.HikariPool.checkFailFast(HikariPool.java:561) ~[HikariCP-4.0.3.jar!/:na]
backend_containerfile | at com.zaxxer.hikari.pool.HikariPool.<init>(HikariPool.java:115) ~[HikariCP-4.0.3.jar!/:na]
backend_containerfile | at com.zaxxer.hikari.HikariDataSource.getConnection(HikariDataSource.java:112) ~[HikariCP-4.0.3.jar!/:na]
backend_containerfile | at org.hibernate.engine.jdbc.connections.internal.DatasourceConnectionProviderImpl.getConnection(DatasourceConnectionProviderImpl.java:122) ~[hibernate-core-5.6.12.Final.jar!/:5.6.12.Final]
What I tried:
1)I tried docker volume prune.
2)I tried removing the
- MYSQL_USER=testuser
- MYSQL_PASSWORD=testuser@123
spring.datasource.username=testuser
spring.datasource.password= testuser@123`
and only going with
- MYSQL_ROOT_PASSWORD=////////////
3)I tried both
spring.datasource.driver-class-name= com.mysql.cj.jdbc.Driver spring.datasource.driver-class-name= com.mysql.jdbc.Driver
4)I put allowPublicKeyRetrieval=true in spring.datasource.url
And many other thing I tried but the result remained the same.
Sorry, for the long question but I really tried to figure out the problem by myself but now I need someone’s insight. And thank you.
2
Answers
Thankfully I found the problem it was because I haven't connected the database and spring io. I will post the solution for my case, in case it helps someone.
then run the following commands in the project terminal:
try to use this driverClassName in application.properties
Have you tried to start only Mysql db in the container and connect to it from you IDE?