I have a spring app in a docker container which should connect to postgresql DB on host
docker-compose.yml
version: '3.8'
services:
spring-app-container:
image: spring-app:1
build:
context: ./
dockerfile: Dockerfile
ports:
- "50700:50700"
environment:
- DATABASE_HOST=192.168.65.2
- DATABASE_USER=user
- DATABASE_PASSWORD=****
- DATABASE_NAME=db_name
- DATABASE_PORT=5432
From the docker container I can ping the DB host IP and I can telnet 192.168.65.2 5432.
postgres configurations are:
pg_hba.conf
# IPv4 local connections:
host all all 0.0.0.0/0 scram-sha-256
and
postgresql.conf
listen_addresses = '*' # what IP address(es) to listen on;
Now when I start docker-compose up, it says:
org.postgresql.util.PSQLException: Connection to localhost:5432 refused.
Check that the hostname and port are correct and that the postmaster is accepting TCP/IP connections.
Why does it say localhost here? In the docker-compose.yml the DB host is set to DATABASE_HOST=192.168.65.2
I also have DB settings in application.properties.
spring.datasource.driver-class-name=org.postgresql.Driver
spring.datasource.url=jdbc:postgresql://localhost:5432/db_name
spring.datasource.username=user
spring.datasource.password=****
Will this be overwritten or do I need to set this to 192.168.65.2 instead of localhost as well?
Am I missing something else here?