-1

I have created a docker image for my spring boot application but i am not able to get that to run. Kindly help me figure this out

java.sql.SQLNonTransientConnectionException: Socket fail to connect to host:address=(host=localhost)(port=3306)(type=primary). Connection refused
.
.

2023-04-25T13:04:41.969Z  WARN 1 --- [           main] o.h.e.j.e.i.JdbcEnvironmentInitiator     : HHH000342: Could not obtain connection to query metadata

java.sql.SQLNonTransientConnectionException: Socket fail to connect to host:address=(host=localhost)(port=3306)(type=primary). Connection refused
Jens
  • 67,715
  • 15
  • 98
  • 113
  • sorry i was not able to post all logs – shashwat kumar Apr 25 '23 at 13:23
  • 1
    I doubt that your docker container contains MySQL... `localhost` for your app is inside the docker container, it won't access anything outside it. – M. Deinum Apr 25 '23 at 13:28
  • Welcome to stack overflow. In order for folks to help you better, please make sure to share some more details. What does you docker image look like? What's you environment? – Rick Rackow Apr 25 '23 at 13:33
  • Please show us the configuration you are using: Dockerfile or the name of the docker image you used, env vars, error logs, etc.. From the first site looking at the log you attached, it seems like you are trying to access a database that is on the machine itself, I assume that the machine has another hostname. Find the host name and then change the configuration in your application to reach to correct db host. – user15937765 Apr 25 '23 at 17:57

1 Answers1

0

Use --network="host" in your docker run command, then 127.0.0.1 in your docker container will point to your docker host. You can get more info and a possible duplicate of this.

Lakshitha Wisumperuma
  • 1,574
  • 1
  • 10
  • 17