简体   繁体   中英

Authentication issue: spring-boot application with postgresql running on docker

I try to connect my spring boot application and PostgreSQL which is in a docker container. When I launch my docker-compose, docker create a container and database with the user I set it in this file. every thing is ok until here.

But when I try to connect my spring application and this container I get this error :

org.postgresql.util.PSQLException: FATAL: authentification par mot de passe échouée pour l'utilisateur  « postgres » (pgjdbc: autodetected server-encoding to be ISO-8859-1, if the message is not readable, please check database logs and/or host, port, dbname, user, password, pg_hba.conf)

The message is in French, In general it can't connect to my database with that user postgres.

My docker-compose.yml

version: '3.5'
services:
  postgres:
    container_name: postgres_container
    image: postgres
    environment:
      POSTGRES_USER: ${POSTGRES_USER:-postgres}
      POSTGRES_PASSWORD: ${POSTGRES_PASSWORD:-password}
      POSTGRES_DB: ${POSTGRES_DB:-dbname}
      PGDATA: /data/postgres
    volumes:
      - postgres:/data/postgres
    ports:
      - "5432:5432"
    networks:
      - postgres
    restart: unless-stopped

and my application.property

spring.datasource.url=jdbc:postgresql://localhost:5432/dbname
spring.datasource.driver-class-name=org.postgresql.Driver
spring.datasource.username=postgres
spring.datasource.password=password
spring.jpa.properties.hibernate.dialect = org.hibernate.dialect.PostgreSQLDialect
spring.jpa.hibernate.ddl-auto=none

any one have an idea about this issue please?

I'm not sure but I assume it's an issue with the defined network. As per default standalone containers use the default network / bridge from docker which offers basic networking functionality. But since you defined a custom network, I assume your spring-app which is running on your host system is not able to reach your container.

Try to remove the networks part and try it.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM