Spring Boot cannot connect to PostgreSQL in Docker
11:32 16 Jun 2026

I'm having a persistent issue with Spring Boot 3.5.15 connecting to PostgreSQL 16 running in Docker. I keep getting:

FATAL: password authentication failed for user "attendance"

What I've tried:

Docker container runs with correct environment variables:

docker run --name postgres -e POSTGRES_USER=attendance -e POSTGRES_PASSWORD=attendance -e POSTGRES_DB=attendance -p 5432:5432 -d postgres:16

I can connect successfully from command line:

docker exec -it postgres psql -U attendance -d attendance

# Successfully connects! Shows: attendance=#

User exists in database:

SELECT usename FROM pg_user;

-- Returns: attendance

-- Returns: attendance

Environment variables are correct:

docker exec -it postgres env | findstr POSTGRES_PASSWORD
-- Returns: POSTGRES_PASSWORD=attendance

My application.properties

spring.banner.location=classpath:banner.txt

logging.level.org.springframework.boot.context.config=DEBUG
spring.application.name=attendance
server.port=8082

logging.level.org.springframework.boot.autoconfigure.jdbc=DEBUG
logging.level.org.hibernate=DEBUG
logging.level.com.zaxxer.hikari=DEBUG

# PostgreSQL 
spring.datasource.url=jdbc:postgresql://localhost:5432/attendance
spring.datasource.username=attendance
spring.datasource.password=attendance
spring.datasource.driver-class-name=org.postgresql.Driver

# JPA 
spring.jpa.hibernate.ddl-auto=update
spring.jpa.show-sql=true
spring.jpa.properties.hibernate.dialect=org.hibernate.dialect.PostgreSQLDialect
spring.security.oauth2.client.registration.keycloak.client-id=spring-app
spring.security.oauth2.client.registration.keycloak.client-secret=cjz4coFQLQ605LxdWvxGUQB2EBK2BOgD
spring.security.oauth2.client.registration.keycloak.scope=openid,profile,email
spring.security.oauth2.client.registration.keycloak.authorization-grant-type=authorization_code
spring.security.oauth2.client.registration.keycloak.redirect-uri=http://localhost:8082/login/oauth2/code/keycloak
spring.security.oauth2.client.provider.keycloak.issuer-uri=http://localhost:8080/realms/university

# Domain for Keycloak
university.allowed-domain=etf.unibl.org

I can connect perfectly from the command line using the exact same credentials, but Spring Boot always fails with "password authentication failed". This suggests the issue is with Spring Boot, not the database.

Full Error:

org.postgresql.util.PSQLException: FATAL: password authentication failed for user "attendance"
    at org.postgresql.core.v3.ConnectionFactoryImpl.doAuthentication(ConnectionFactoryImpl.java:835)
    ... (more stack trace)

What am I missing? Why does Spring Boot reject the same credentials that work from the command line?

Additional info: I'm using IntelliJ IDEA Community Edition 2024.2.1 with Spring Boot DevTools enabled.

pom.xml dependencies:



    4.0.0
    
       org.springframework.boot
       spring-boot-starter-parent
       3.5.15
        
    
    com.university
    attendance
    0.0.1-SNAPSHOT
    
    
    
    
       
    
    
       
    
    
       
       
       
       
    
    
       17
    
    

       
       
          org.springframework.boot
          spring-boot-starter-data-jpa
       

       
       
          org.postgresql
          postgresql
          runtime
       

       
       
          org.apache.poi
          poi-ooxml
          5.2.5
       

       
          org.springframework.boot
          spring-boot-starter-oauth2-client
       
       
          org.springframework.boot
          spring-boot-starter-security
       
       
          org.springframework.boot
          spring-boot-starter-thymeleaf
       
       
          org.springframework.boot
          spring-boot-starter-web
       
       
          org.thymeleaf.extras
          thymeleaf-extras-springsecurity6
       

       
          org.springframework.boot
          spring-boot-devtools
          runtime
          true
       
       
          org.springframework.boot
          spring-boot-starter-test
          test
       
       
          org.springframework.security
          spring-security-test
          test
       
    

    
       
          
             org.springframework.boot
             spring-boot-maven-plugin
          
       
    


postgresql spring-boot docker spring-data-jpa