[英]Authentication issue: spring-boot application with postgresql running on docker
我尝试连接我的 spring 启动应用程序和 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
有人对这个问题有想法吗?
我不确定,但我认为这是定义网络的问题。 默认独立容器使用来自 docker 的默认网络/网桥,它提供基本的网络功能。 但是由于您定义了自定义网络,因此我假设您在主机系统上运行的 spring-app 无法访问您的容器。
尝试删除网络部分并尝试。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.