[英]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.我尝试连接我的 spring 启动应用程序和 docker 容器中的 PostgreSQL。 When I launch my docker-compose, docker create a container and database with the user I set it in this file.
当我启动我的 docker-compose 时,docker 会使用我在这个文件中设置的用户创建一个容器和数据库。 every thing is ok until here.
一切都好,直到这里。
But when I try to connect my spring application and this container I get this error :但是当我尝试连接我的 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)
The message is in French, In general it can't connect to my database with that user postgres.该消息是法语,通常它无法使用该用户 postgres 连接到我的数据库。
My docker-compose.yml我的 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和我的 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.
默认独立容器使用来自 docker 的默认网络/网桥,它提供基本的网络功能。 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.
但是由于您定义了自定义网络,因此我假设您在主机系统上运行的 spring-app 无法访问您的容器。
Try to remove the networks part and try it.尝试删除网络部分并尝试。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.