I am building a microservices application using Spring Boot, and I am running two distinct postgres containers on docker for two of the microservices running on my local machine (Windows 10). The docker-compose.yml file is as follows:
services:
notification-postgres:
container_name: notification-postgres
image: postgres
environment:
POSTGRES_DB: notification_service_db
POSTGRES_USER: admin
POSTGRES_PASSWORD: admin123
PGDATA: /var/lib/postgresql/data
volumes:
- notification-postgres:/var/lib/postgresql/data
ports:
- "5432:5432"
restart: unless-stopped
auth-postgres:
container_name: auth-postgres
image: postgres
environment:
POSTGRES_DB: auth_service_db
POSTGRES_USER: admin
POSTGRES_PASSWORD: admin123
PGDATA: /var/lib/postgresql/data
volumes:
- auth-postgres:/var/lib/postgresql/data
ports:
- "5431:5431"
expose:
- 5431
command: -p 5431
restart: unless-stopped
volumes:
notification-postgres:
auth-postgres:
The application.yml for notification service is as follows:
spring:
datasource:
url: jdbc:postgresql://localhost:5432/notification_service_db
username: admin
password: admin123
driver-class-name: org.postgresql.Driver
jpa:
hibernate:
ddl-auto: update
The application.yml for atuh service is as follows:
spring:
datasource:
url: jdbc:postgresql://localhost:5431/auth_service_db
username: admin
password: admin123
driver-class-name: org.postgresql.Driver
jpa:
hibernate:
ddl-auto: update
I was able to connect to notification-postgres from my IDE (IntelliJ IDEA) by stopping the postgres.exe service (as instructed here), which is installed in my local machine.
But, as for the auth-postgres, which runs on ports "5431:5431", I am getting the following error:
org.postgresql.util.PSQLException: FATAL: password authentication failed for user "admin"
However, I am able to connect to it using psql, and it is working fine. Here are some logs:
docker logs auth-postgres:
...
2025-08-04 12:12:36.349 UTC [1] LOG: starting PostgreSQL 17.5 (Debian 17.5-1.pgdg120+1) on x86_64-pc-linux-gnu, compiled by gcc (Debian 12.2.0-14) 12.2.0, 64-bit
2025-08-04 12:12:36.350 UTC [1] LOG: listening on IPv4 address "0.0.0.0", port 5431
2025-08-04 12:12:36.350 UTC [1] LOG: listening on IPv6 address "::", port 5431
2025-08-04 12:12:36.354 UTC [1] LOG: listening on Unix socket
Overall, I cannot connect to multiple postgres containers with my IDE. If anyone knows how to fix the issue, your solutions are welcome.