Home > Software design >  FATAL: password authentication failed for user "admin" Docker and Spring boot
FATAL: password authentication failed for user "admin" Docker and Spring boot

Time:08-11

I have a sping boot application and here is my application.yml file.


# postgres sql connection
spring:
  datasource:
    password: password
    url: jdbc:postgresql://127.0.0.1:5432/todos
    username: admin
  jpa:
    hibernate:
      ddl-auto: create #create
    properties:
      hibernate:
        dialect: org.hibernate.dialect.PostgreSQLDialect
        format_sql: true
    show-sql: true
# Configuring the port for our server
server:
  port: 3001

And here is my docker-compose.yml file:

version: "3.9"
services:
  postgresdb:
    image: postgres:14.4-alpine
    container_name: pgsql
    restart: always
    volumes:
      - ./db/init.sql:/docker-entrypoint-initdb.d/0_init.sql
      # - $HOME/database:/var/lib/postgresql/data
    ports:
      - "5232:5432"
    expose:
      - "5232"
    environment:
      POSTGRES_DB: todos
      POSTGRES_USER: admin
      POSTGRES_PASSWORD: password
      SERVICE_NAME: postgresdb
    networks:
      - internalnet

networks:
  internalnet:
    driver: bridge

My postgres container is already running, but when i try to connect my spring application with docker i get the following error:


org.postgresql.util.PSQLException: FATAL: password authentication failed for user "admin"

If i run ps command:

CONTAINER ID   IMAGE                  COMMAND                  CREATED         STATUS                          PORTS                               NAMES
a7035cd521a6   postgres:14.4-alpine   "docker-entrypoint.s…"   7 minutes ago   Up 7 minutes                    5232/tcp, 0.0.0.0:5232->5432/tcp    pgsql

What may be possibly my problem here?

CodePudding user response:

Your spring boot application should be contacting the postgres db on port 5232 since that is what you are port forwarding from the db container (not 5432).

  • Related