1

Im getting the connection refused error, but in my eclipse it connects with no problem. I wonder if it is not possible to connect to a database that hasnt been dockerized also or if its possible what should I do?

thise is my Dockerfile:

FROM openjdk:11
EXPOSE 8080
ADD target/permisos.jar permisos.jar
ENTRYPOINT ["java","-jar","/permisos.jar"]

this is my application.yml file:

spring:
  profiles:
    active: local
  jpa:
    database: POSTGRESQL
    show-sql: true
    hibernate:
      ddl-auto: none
  datasource:
    platform: postgres
    url: jdbc:postgresql://localhost:5432/permisosdb
    username: postgres
    password: postgres
    driverClassName: org.postgresql.Driver
BugsForBreakfast
  • 712
  • 10
  • 30

1 Answers1

1

The IP address of the host is host.docker.internal on, AFAIK, all modern Docker installations.

So your datasource URL should be

url: jdbc:postgresql://host.docker.internal:5432/permisosdb

If that doesn't work, try

url: jdbc:postgresql://172.17.0.1:5432/permisosdb
Hans Kilian
  • 18,948
  • 1
  • 26
  • 35
  • Perfect, thank you very much it worked with the first method, it would be cool if you could add the source of this information, so I can study more about this kind of configurations – BugsForBreakfast Oct 20 '21 at 07:26
  • 1
    I tried seeing if I could find something in the official docs. The best I found is this where it's listed as a workaround: https://docs.docker.com/desktop/windows/networking/#use-cases-and-workarounds. On re-reading it I can see that it seems that how you reach the host is still dependent on your host OS. The `host.docker.internal` is for Windows. `172.17.0.1` is for Linux. I don't know about Mac. – Hans Kilian Oct 20 '21 at 07:48
  • Perfect, good to take notes about it for the future, cheers – BugsForBreakfast Oct 20 '21 at 13:33