SpringBoot on Docker unable to connect to MySQL - mysql

I have written docker compose for my SpringBoot app with MySQL. When I run docker-compose up eventually I get an error:
The last packet sent successfully to the server was 0 milliseconds ago. The driver has not received any packets from the server.
at org.springframework.jdbc.datasource.DataSourceUtils.getConnection(DataSourceUtils.java:80) ~[spring-jdbc-4.3.17.RELEASE.jar!/:4.3.17.RELEASE]
at org.springframework.jdbc.support.JdbcUtils.extractDatabaseMetaData(JdbcUtils.java:325) ~[spring-jdbc-4.3.17.RELEASE.jar!/:4.3.17.RELEASE]
... 69 common frames omitted
Caused by: 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.
at com.mysql.cj.jdbc.exceptions.SQLError.createCommunicationsException(SQLError.java:172) ~[mysql-connector-java-8.0.11.jar!/:8.0.11]
at com.mysql.cj.jdbc.exceptions.SQLExceptionsMapping.translateException(SQLExceptionsMapping.java:64) ~[mysql-connector-java-8.0.11.jar!/:8.0.11]
at com.mysql.cj.jdbc.ConnectionImpl.createNewIO(ConnectionImpl.java:862) ~[mysql-connector-java-8.0.11.jar!/:8.0.11]
at com.mysql.cj.jdbc.ConnectionImpl.<init>(ConnectionImpl.java:444) ~[mysql-connector-java-8.0.11.jar!/:8.0.11]
at com.mysql.cj.jdbc.ConnectionImpl.getInstance(ConnectionImpl.java:230) ~[mysql-connector-java-8.0.11.jar!/:8.0.11]
at com.mysql.cj.jdbc.NonRegisteringDriver.connect(NonRegisteringDriver.java:226) ~[mysql-connector-java-8.0.11.jar!/:8.0.11]
at java.sql.DriverManager.getConnection(DriverManager.java:664) ~[na:1.8.0_111]
at java.sql.DriverManager.getConnection(DriverManager.java:208) ~[na:1.8.0_111]
at org.springframework.jdbc.datasource.DriverManagerDataSource.getConnectionFromDriverManager(DriverManagerDataSource.java:153) ~[spring-jdbc-4.3.17.RELEASE.jar!/:4.3.17.RELEASE]
at org.springframework.jdbc.datasource.DriverManagerDataSource.getConnectionFromDriver(DriverManagerDataSource.java:144) ~[spring-jdbc-4.3.17.RELEASE.jar!/:4.3.17.RELEASE]
at org.springframework.jdbc.datasource.AbstractDriverBasedDataSource.getConnectionFromDriver(AbstractDriverBasedDataSource.java:196) ~[spring-jdbc-4.3.17.RELEASE.jar!/:4.3.17.RELEASE]
at org.springframework.jdbc.datasource.AbstractDriverBasedDataSource.getConnection(AbstractDriverBasedDataSource.java:159) ~[spring-jdbc-4.3.17.RELEASE.jar!/:4.3.17.RELEASE]
at org.springframework.jdbc.datasource.DataSourceUtils.doGetConnection(DataSourceUtils.java:111) ~[spring-jdbc-4.3.17.RELEASE.jar!/:4.3.17.RELEASE]
at org.springframework.jdbc.datasource.DataSourceUtils.getConnection(DataSourceUtils.java:77) ~[spring-jdbc-4.3.17.RELEASE.jar!/:4.3.17.RELEASE]
... 70 common frames omitted
Caused by: com.mysql.cj.exceptions.CJCommunicationsException: Communications link failure
At first I thought the the cause was the db but I managed to run local instance of the app and connect to the docker mysql.
Next I assumed that the spring app tries to connect to mysql before it is up and running but I restarted the app (mysql was already running) and got the same error.
Currently I think that this might be caused by the windows10 firewall but I am running low on ideas.
Dockerfile:
FROM java:8
LABEL maintainer="maciej"
WORKDIR /app
COPY target/kamienica.jar /app/kamienica.jar
ENTRYPOINT ["java", "-jar","kamienica.jar", "--spring.profiles.active=docker"]
docker-compose.yml
version: '3'
services:
mysql-docker-container:
image: mysql:latest
environment:
- MYSQL_ROOT_PASSWORD=maciej
- MYSQL_DATABASE=kamienica
- MYSQL_USER=maciej
- MYSQL_PASSWORD=maciej
volumes:
- /data/mysql
ports:
- 3333:3306
container_name: kamienica-db
kamienica-app:
image: kamienica-image
build:
context: ./
dockerfile: Dockerfile
depends_on:
- mysql-docker-container
ports:
- 8080:8080
volumes:
- /data/spring-boot-app
container_name: kamienica-app
and the application-docker.properties:
jdbc.url = jdbc:mysql://kamienica-db:3333/kamienica?useSSL=false&characterEncoding=UTF-8&useJDBCCompliantTimezoneShift=true&useLegacyDatetimeCode=false&serverTimezone=UTC
jdbc.username = maciej
jdbc.password = maciej
hibernate.show_sql = true
hibernate.format_sql = true
hibernate.hbm2ddl.auto=create-drop
hibernate.dialect=org.hibernate.dialect.MySQLDialect
hibernate.current_session_context_class=thread
hibernate.connection.characterEncoding=UTF-8
hibernate.connection.charSet=UTF-8

Try to change the url into this your properties file
jdbc:mysql://mysql-docker-container:3306/kamienica

jdbc:mysql://[mysql-docker-container-name]:[mysql-port]/[db-name]
in your docker-compose.yml mysql-docker-container-name is mysql-docker-container
so change your spring boot application.properties file mysql url as following
jdbc:mysql://mysql-docker-container:3306/kamienica

Related

Spring Boot Application not able to connect with MySQL in Docker

While I am going to start my spring boot application image in the docker engine with the below command then I am getting an error
The command which I am using to start my application image
docker run -p 8082:8082 --name e-health e-health
GETTING BELOW ERROR
The last packet sent successfully to the server was 0 milliseconds ago. The driver has not received any packets from the server.
at sun.reflect.NativeConstructorAccessorImpl.newInstance0(Native Method) ~[na:1.8.0_212]
at sun.reflect.NativeConstructorAccessorImpl.newInstance(NativeConstructorAccessorImpl.java:62) ~[na:1.8.0_212]
at sun.reflect.DelegatingConstructorAccessorImpl.newInstance(DelegatingConstructorAccessorImpl.java:45) ~[na:1.8.0_212]
at java.lang.reflect.Constructor.newInstance(Constructor.java:423) ~[na:1.8.0_212]
at com.mysql.cj.exceptions.ExceptionFactory.createException(ExceptionFactory.java:61) ~[mysql-connector-java-8.0.23.jar!/:8.0.23]
at com.mysql.cj.exceptions.ExceptionFactory.createException(ExceptionFactory.java:105) ~[mysql-connector-java-8.0.23.jar!/:8.0.23]
at com.mysql.cj.exceptions.ExceptionFactory.createException(ExceptionFactory.java:151) ~[mysql-connector-java-8.0.23.jar!/:8.0.23]
at com.mysql.cj.exceptions.ExceptionFactory.createCommunicationsException(ExceptionFactory.java:167) ~[mysql-connector-java-8.0.23.jar!/:8.0.23]
at com.mysql.cj.protocol.a.NativeSocketConnection.connect(NativeSocketConnection.java:89) ~[mysql-connector-java-8.0.23.jar!/:8.0.23]
at com.mysql.cj.NativeSession.connect(NativeSession.java:144) ~[mysql-connector-java-8.0.23.jar!/:8.0.23]
at com.mysql.cj.jdbc.ConnectionImpl.connectOneTryOnly(ConnectionImpl.java:953) ~[mysql-connector-java-8.0.23.jar!/:8.0.23]
at com.mysql.cj.jdbc.ConnectionImpl.createNewIO(ConnectionImpl.java:823) ~[mysql-connector-java-8.0.23.jar!/:8.0.23]
... 57 common frames omitted
Caused by: java.net.UnknownHostException: mysqldb
at java.net.InetAddress.getAllByName0(InetAddress.java:1281) ~[na:1.8.0_212]
at java.net.InetAddress.getAllByName(InetAddress.java:1193) ~[na:1.8.0_212]
at java.net.InetAddress.getAllByName(InetAddress.java:1127) ~[na:1.8.0_212]
at com.mysql.cj.protocol.StandardSocketFactory.connect(StandardSocketFactory.java:132) ~[mysql-connector-java-8.0.23.jar!/:8.0.23]
at com.mysql.cj.protocol.a.NativeSocketConnection.connect(NativeSocketConnection.java:63) ~[mysql-connector-java-8.0.23.jar!/:8.0.23]
... 60 common frames omitted
I have created a MySQL container with the below command
docker run -d -p 3306:3306 --name mysqldb -e MYSQL_ROOT_PASSWORD=123456789 -e MYSQL_DATABASE=eHealth mysql
I have created my Spring boot application Image with below command
docker build -t e-health .
My Spring Boot project application.properties file looks like below
spring.datasource.name=eHealth
spring.datasource.url=jdbc:mysql://mysqldb:3306/eHealth
spring.datasource.username=root
spring.datasource.password=123456789
spring.datasource.driver-class-name=com.mysql.cj.jdbc.Driver
spring.jpa.properties.hibernate.dialect=org.hibernate.dialect.MySQL8Dialect
spring.jpa.hibernate.ddl-auto=update
spring.jpa.show-sql=true
server.port=8082
My Dockerfile looks like below
FROM openjdk:8-jdk-alpine
ARG JAR_FILE=target/eHealth.jar
WORKDIR /opt/app
COPY ${JAR_FILE} app.jar
ENTRYPOINT ["java","-jar","app.jar"]
Docker container Looks like
I have followed the below question but it's not helping me
Spring Boot MySQL Docker Caused by: java.net.ConnectException: Connection refused (Connection refused)
Any suggestions or solutions, Please
As per the suggestion I have tried to create a container like below also, But still I am getting the same error
docker run -d -p 3306:3306 --name mysqldb --hostname=mysqldb -e MYSQL_ROOT_PASSWORD=123456789 -e MYSQL_DATABASE=eHealth MySQL
CONTAINER ID IMAGE COMMAND CREATED STATUS PORTS NAMES
469e171ff3e2 mysql "docker-entrypoint.s…" 5 seconds ago Up 4 seconds 0.0.0.0:3306->3306/tcp, 33060/tcp mysqldb
it depends on your use case if you are trying to run both the spring boot application and MySQL in docker, you need to make sure that both containers are in the same network.
one solution is to manually create the networks using the docker command and run both container on this created network. or an easier solution is to write a docker-compose.yml file
by default the docker-compose.yml will create a default network.
docker-compose.yml
version: '3'
services:
mysql-standalone:
image: mysql:latest
environment:
- MYSQL_ROOT_PASSWORD=***
- MYSQL_DATABASE=***
- MYSQL_USER=***
- MYSQL_PASSWORD=**
volumes:
- data:/var/lib/mysql
spring-boot:
image: *your-app-name-image*
ports:
[8080:8080]
build:
context: ./
dockerfile: Dockerfile
depends_on:
- mysql-standalone
volumes:
data:
you can also create your own network like the following
networks:
mynetwork:
driver: bridge
so your docker-compose.yml file will look like the following
version: '3'
services:
mysql-standalone:
image: mysql:latest
environment:
- MYSQL_ROOT_PASSWORD=***
- MYSQL_DATABASE=***
- MYSQL_USER=***
- MYSQL_PASSWORD=**
volumes:
- data:/var/lib/mysql
networks:
- mynetwork
spring-boot:
image: *your-app-name-image*
ports:
[8080:8080]
build:
context: ./
dockerfile: Dockerfile
depends_on:
- mysql-standalone
networks:
- mynetwork
volumes:
data:
networks:
mynetwork:
driver: bridge
in your application.yml file you need to have the following
server.port=8080
spring.datasource.url=jdbc:mysql://<container-name>:3306/<db-name>
spring.datasource.username=***
spring.datasource.password=***
I would suggest having multiple profiles using the spring profile.
The second use case is if you are running MySQL in a container and your spring boot application locally, then you need to change this:
spring.datasource.url=jdbc:mysql://mysqldb:3306/eHealth
to
spring.datasource.url=jdbc:mysql://localhost:3306/eHealth
this should solve the error mentioned Caused by: java.net.UnknownHostException: mysqldb.
if you decided that writing a docker-compose.yml file does not suit your use case, check this https://docs.docker.com/engine/reference/commandline/network_create/ to check how to create networks from the command line

Docker compose service not connecting to mysql container

I am trying to connect my service to MySQL docker container via docker-compose. The connection is refused. I tried to run MySQL docker image and connect my running service to it locally. the connection is established and everything is working fine. The problem is when I want to run both the service and MySQL container, the connection is refused. I created the custom network and tried many solutions but it has already taken me 2 days!
the docker compose configs are:
version : '3.8'
services:
healthcare:
build:
context: .
dockerfile: Dockerfile
ports:
- "8080:8080"
depends_on:
- mysql
restart: always
environment:
RDS_URL: mysql
networks:
- saman-network
mysql:
image: mysql:8-oracle
container_name:
mysql
environment:
MYSQL_ROOT_PASSWORD: root
MYSQL_DATABASE: hospital_db
MYSQL_USER: saman
MYSQL_PASSWORD: saman
volumes:
- myvolume:/var/lib/mysql
ports:
- "3308:3306"
networks:
- saman-network
volumes:
myvolume:
networks:
saman-network:
the application.properties configs are:
server.port=8080
spring.application.name=healthcare
spring.datasource.url=jdbc:mysql://${RDS_URL:localhost}:3308/hospital_db
spring.datasource.username=saman
spring.datasource.password=saman
spring.jpa.properties.hibernate.dialect = org.hibernate.dialect.MySQLDialect
spring.jpa.show-sql=true
spring.jpa.hibernate.ddl-auto=update
spring.datasource.driver-class-name=com.mysql.cj.jdbc.Driver
the error I am getting:
springboot-hospitalmng-sample-healthcare-1 | ... 46 common frames omitted
springboot-hospitalmng-sample-healthcare-1 | Caused by: com.mysql.cj.exceptions.CJCommunicationsException: Communications link failure
and
springboot-hospitalmng-sample-healthcare-1 | ... 59 common frames omitted
springboot-hospitalmng-sample-healthcare-1 | Caused by: java.net.ConnectException: Connection refused
springboot-hospitalmng-sample-healthcare-1 | at java.base/sun.nio.ch.Net.pollConnect(Native Method) ~[na:na]
springboot-hospitalmng-sample-healthcare-1 | at java.base/sun.nio.ch.Net.pollConnectNow(Net.java:672) ~[na:na]
springboot-hospitalmng-sample-healthcare-1 | at java.base/sun.nio.ch.NioSocketImpl.timedFinishConnect(NioSocketImpl.java:542) ~[na:an]
springboot-hospitalmng-sample-healthcare-1 | The last packet sent successfully to the server was 0 milliseconds ago. The driver has not received any packets from the server.
springboot-hospitalmng-sample-healthcare-1 | 2023-01-05T14:20:37.165Z ERROR 1 --- [ main] j.LocalContainerEntityManagerFactoryBean : Failed to initialize JPA EntityManagerFactory: [PersistenceUnit: default] Unable to build Hibernate SessionFactory; nested exception is org.hibernate.exception.JDBCConnectionException: Unable to open JDBC Connection for DDL execution
I think this is the problem. mysql runs on port 3306, you expose it on the host on 3308. But from the configuration you connect through the docker network using RDS_URL but port 3308, it should be 3306 instead

Spring boot + MySQL. Docker

I`m create simple app on spring boot + MySQL. On local pc it works correctly, but when i package it in docker, i catch some errors: container with DB works well, i can connect to it via workbanch, the container with the application crashes on startup with an error:
"java.sql.SQLNonTransientConnectionException: Could not create connection to database server. Attempted reconnect 3 times. Giving up.
...
Caused by: com.mysql.cj.exceptions.CJCommunicationsException: 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.
...
Caused by: java.net.ConnectException: Connection refused
..."
My Dockerfile:
FROM openjdk:17-alpine
ADD /target/tests-0.0.1-SNAPSHOT.jar backend.jar
ENTRYPOINT ["java", "-jar", "backend.jar"]
My docker-compose.yml:
version: '3'
services:
personsdb:
image: 'mysql:8.0.31'
container_name: 'persons-db'
environment:
- 'MYSQL_ROOT_PASSWORD=Qwer'
- 'MYSQL_DATABASE=persons'
- 'MYSQL_USER=mysql'
- 'MYSQL_PASSWORD=Qwer'
ports:
- '3305:3306'
app:
container_name: 'persons-app'
ports:
- 8088:8080
environment:
SPRING_DATASOURCE_URL: jdbc:mysql://personsdb:3305/persons?autoReconnect=true&useSSL=false
depends_on:
- 'personsdb'
build: ./
My application.properties:
spring.jpa.hibernate.ddl-auto=update
spring.datasource.url=jdbc:mysql://personsdb:3305/persons
spring.datasource.username=root
spring.datasource.password=Qwer
spring.datasource.driver-class-name=com.mysql.cj.jdbc.Driver
I tried to
run: docker-compose down --rmi all
rename service
upgrade MySQL Connector
add more dependences to pom.xml
...
It seems you have to create a bridge to let them communicate.
Please check the link below
https://www.tutorialworks.com/container-networking/
when they are in the same host, below configuration also worked for me.
datasource:
driver-class-name: org.postgresql.Driver
url: jdbc:postgresql://host.docker.internal:5432/DB-NAME

Problem with dockercompose connection to MySQL container

I'm having trouble connecting my spring application with the MySQL database.
In particular, I report the code of the docker compose, the docker file, application.yml and the error log.
docker-compose:
version: '3.3'
services:
my-sql-db:
image: mysql:latest
environment:
- MYSQL_ROOT_PASSWORD=user
- MYSQL_USER=user
- MYSQL_DATABASE=spring-app
ports:
- "3306:3306"
customerservice:
image: customer-service
build:
context: .
dockerfile: Dockerfile
ports:
- "8080:8080"
depends_on:
- my-sql-db
environment:
SPRING_PROFILES_ACTIVE: MySQLdocker
Dockerfile:
FROM maven:3.6.3-jdk-8
COPY ./ ./
RUN mvn clean package
EXPOSE 8080
CMD ["java", "-jar", "target/my-spring-project-0.0.1-SNAPSHOT.jar"]
Application.yml:
spring:
jpa:
open-in-view: false #per levare warnig OpenSessionInView
properties:
hibernate:
jdbc:
time_zone: CET
dialect: org.hibernate.dialect.MySQL5InnoDBDialect
hibernate:
ddl-auto: none
datasource:
url: jdbc:mysql://my-sql-db:3306/spring-app?createDatabaseIfNotExist=true
username: user
password: user
config:
activate:
on-profile: MySQLdocker
Executing the command "docker-compose up -d" the output error is:
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.
at com.mysql.cj.jdbc.exceptions.SQLError.createCommunicationsException(SQLError.java:174) ~[mysql-connector-java-8.0.27.jar!/:8.0.27]
at com.mysql.cj.jdbc.exceptions.SQLExceptionsMapping.translateException(SQLExceptionsMapping.java:64) ~[mysql-connector-java-8.0.27.jar!/:8.0.27]
I'm not seeing MYSQL_PASSWORD defined in your docker-compose file.
Generally, the error suggests the app cannot connect to MySQL at all. When you have such a problem that could be caused by many things, you should try and narrow it down. Check if the DB is up and running. If yes, then try to connect to it from some MySQL client. And so on, until you figure out what exactly went wrong or at least come up with a more specific question.

Can't connect a spring-boot 2 service to mysql in a different container

I have a spring-boot 2.16 service that connects to a my-sql data base. It works as expected as far as all the components are on the same host. I tried to improve the solution and to have a docker container running the sprin-boot service with Tomcat embedded and another docker container running the my-sql server.
The same code doesn't work any more. here is the exception:
2019-06-28 12:23:48 ERROR com.zaxxer.hikari.pool.HikariPool - HikariPool-1 - Exception during pool initialization.
com.mysql.jdbc.exceptions.jdbc4.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.
at sun.reflect.NativeConstructorAccessorImpl.newInstance0(Native Method)
at sun.reflect.NativeConstructorAccessorImpl.newInstance(NativeConstructorAccessorImpl.java:62)
at sun.reflect.DelegatingConstructorAccessorImpl.newInstance(DelegatingConstructorAccessorImpl.java:45)
at java.lang.reflect.Constructor.newInstance(Constructor.java:423)
at com.mysql.jdbc.Util.handleNewInstance(Util.java:404)
at com.mysql.jdbc.SQLError.createCommunicationsException(SQLError.java:988)
at com.mysql.jdbc.MysqlIO.<init>(MysqlIO.java:341)
....
Caused by: java.net.ConnectException: Connection refused (Connection refused)
at java.net.PlainSocketImpl.socketConnect(Native Method)
at java.net.AbstractPlainSocketImpl.doConnect(AbstractPlainSocketImpl.java:350)
at java.net.AbstractPlainSocketImpl.connectToAddress(AbstractPlainSocketImpl.java:206)
at java.net.AbstractPlainSocketImpl.connect(AbstractPlainSocketImpl.java:188)
at java.net.SocksSocketImpl.connect(SocksSocketImpl.java:392)
at java.net.Socket.connect(Socket.java:589)
at com.mysql.jdbc.StandardSocketFactory.connect(StandardSocketFactory.java:211)
at com.mysql.jdbc.MysqlIO.<init>(MysqlIO.java:300)
... 66 common frames omitted
So, it's like the my-sql server IP address is not found or the server is not running, etc.
Here is the docker-compse.yml file:
version: "2"
services:
rdf-data:
container_name: rdf-data
image: mysql:latest
environment:
MYSQL_DATABASE: test
MYSQL_USER: nicolas
MYSQL_PASSWORD: mysql
MYSQL_ROOT_PASSWORD: mysql
ports:
- 3306:3306
- 33060:33060
hostname: rdf-data
networks:
net1:
ipv4_address: 192.19.0.4
rdf-core:
image: openjdk:8-jdk-alpine
depends_on:
- rdf-data
container_name: rdf-core
links:
- rdf-data:rdf-data
volumes:
- ../docker:/usr/local/share/rdf
ports:
- "8080:8080"
entrypoint: /usr/local/share/rdf/run.sh
hostname: rdf-core
environment:
PROFILE: "default"
SERVER_PORT: "8080"
networks:
net1:
ipv4_address: 192.19.0.8
networks:
net1:
driver: bridge
driver_opts:
com.docker.network.enable_ipv6: "false"
ipam:
driver: default
config:
- subnet: 192.19.0.0/24
gateway: 192.19.0.1
Here there are two containers: rfd-core having the IP address of 192.19.0.8 and rdf-data having the IP address 192.19.0.4. Each container is able to ping the other. The hst machine is able to ping each container. From the host machine I'm able to correctly connect to the my-sql server running on rfd-data using the my-sql command line client.
However, my service connection shown here below doesn't work:
database=mysql
spring.datasource.url=jdbc:mysql://192.19.0.4/test?useSSL=false
spring.datasource.username=root
spring.datasource.password=mysql
spring.datasource.driver-class=com.mysql.cj.jdbc.MysqlXADataSource
spring.datasource.driver-class-name=com.mysql.jdbc.Driver
spring.datasource.hikari.connectionTimeout=30000
spring.datasource.hikari.idleTimeout=600000
spring.datasource.hikari.maxLifetime=1800000
...
Is there anything I'm missing?
Try specifying the parameters of the spring boot app in the environment part of your docker-compose file :
rdf-core:
image: openjdk:8-jdk-alpine
depends_on:
- rdf-data
container_name: rdf-core
links:
- rdf-data:rdf-data
volumes:
- ../docker:/usr/local/share/rdf
ports:
- "8080:8080"
entrypoint: /usr/local/share/rdf/run.sh
hostname: rdf-core
environment:
PROFILE: "default"
SERVER_PORT: "8080"
spring.datasource.url=jdbc:mysql://ipaddress/test?useSSL=false
spring.datasource.username=root
spring.datasource.password=mysql
spring.datasource.driver-class=com.mysql.cj.jdbc.MysqlXADataSource
spring.datasource.driver-class-name=com.mysql.jdbc.Driver
spring.datasource.hikari.connectionTimeout=30000
spring.datasource.hikari.idleTimeout=600000
spring.datasource.hikari.maxLifetime=1800000
Another possible cause of the problem : the depends_on doesn't guarantee that the dependency container is fully running. so if the MySQL containers takes more time to fully start than the Spring Boot container, the connection fails.
Take a look at this:
Spring Boot + docker-compose + MySQL: Connection refused
There are few possible ways to make a container wait for another:
Use the restart on failure feature, or docker compose wait (
Github link )