简体   繁体   English

身份验证问题:在 docker 上运行 postgresql 的 spring-boot 应用程序

[英]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.

相关问题 从 spring-boot 连接到 PostgreSQL 副本 - connecting from spring-boot to PostgreSQL replica Spring Boot、PostgreSQL 和 Docker - 在容器中运行时连接被拒绝 - Spring Boot, PostgreSQL, and Docker - Connection Refused whil Running in Container 使用远程 PostgreSQL Db 将 Spring-Boot 应用程序部署到远程服务器的问题 - Problem to deploy Spring-Boot Application to Remote server with remote PostgreSQL Db 使用Spring Boot Application时如何解决PostgreSQL问题 - How to resolve PostgreSQL issue when using Spring Boot Application 将 PostgreSQL 数据库连接到 Spring 应用程序(均在 docker 中运行)连接被拒绝 - Connecting PostgreSQL database to Spring application (both running in docker) Connection refused 如何使用spring-boot和postgresql的postgis类型地理? - How to use postgis type Geography with spring-boot and postgresql? Spring-Boot PostgreSQL尝试连接时抛出异常? - Spring-Boot PostgreSQL exception thrown trying to connect? 访问 postgresql 数据库导致 Spring-Boot 出现语法错误 - Syntax Error in Spring-Boot by eccessing postgresql database 关于运行我的java spring-boot项目的InvocationTargetException - InvocationTargetException on running my java spring-boot project 使用Gradle和Docker部署Spring Boot / PostgreSQL项目 - Deploy of Spring Boot/PostgreSQL project with Gradle and Docker
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM