【问题标题】:Authentication issue: spring-boot application with postgresql running on docker身份验证问题:在 docker 上运行带有 postgresql 的 spring-boot 应用程序
【发布时间】:2020-05-29 15:09:43
【问题描述】:

我尝试连接我的 Spring Boot 应用程序和 Docker 容器中的 PostgreSQL。 当我启动 docker-compose 时,docker 使用我在此文件中设置的用户创建一个容器和数据库。 到这里为止,一切都很好。

但是当我尝试连接我的 spring 应用程序和这个容器时,我得到了这个错误:

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)

消息是法语的,一般情况下,它无法使用该用户 postgres 连接到我的数据库。

我的 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

还有我的 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

请问有人知道这个问题吗?

【问题讨论】:

    标签: postgresql spring-boot docker


    【解决方案1】:

    我不确定,但我认为这是定义的网络的问题。根据默认的独立容器使用来自 docker 的默认网络/网桥,它提供基本的网络功能。但是由于您定义了一个自定义网络,我假设您在主机系统上运行的 spring-app 无法访问您的容器。

    尝试删除网络部分并尝试。

    【讨论】:

      猜你喜欢
      • 2018-04-16
      • 2019-02-13
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2018-04-15
      • 2019-04-25
      • 2017-12-12
      • 1970-01-01
      相关资源
      最近更新 更多