Hi all,
I’ve a microservice that allows me to connect to a oracle db, when I ran with Springboot all connection went ok, but when I try to run it with this command :
docker run -p 8081:8080 pecodb:springboot-v2-new
I receive this error :
2024-03-07T07:12:44.422Z INFO 1 --- [ main] com.zaxxer.hikari.HikariDataSource : HikariPool-1 - Starting...
2024-03-07T07:12:45.510Z ERROR 1 --- [ main] com.zaxxer.hikari.pool.HikariPool : HikariPool-1 - Exception during pool initialization.
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.
I’ve also had this error when I try to connect to my previous localhost MySQL DB
How can I resolve it?
Thanks for all your support
You’ve gonna have to provide a few more details.
When you say “when I try to run it”, I assume the it in this case is your application? So you’ve build a fat jar, and wrapped it in a Docker image?
I think your problem here is Docker-specific. I’m assuming the database you want your application to connect to lives outside of the Docker container where your application is running.
By default, an application inside a Docker container can only access other things running inside the same Docker container. It can’t access anything on the host, or anything inside any other Docker containers. If you want it to be able to access stuff outside the Docker container, you have to configure the Docker container to allow that.
I’m not actually sure how to configure a Docker container to access stuff on the host, but if you look up the docs, it should be pretty easy to figure out.
Note that -p 8081:8080
is allowing things from outside the Docker container to send traffic into the container, NOT the other way around.
Also a final note, I really think this is a Docker question, not a Kotlin question. You’re lucky that some people here know Docker; the Docker forums would be a much better place for this question.