postgresql Keycloak Postgres停靠程序连接失败

ndasle7k  于 2022-11-04  发布在  PostgreSQL
关注(0)|答案(2)|浏览(257)

我尝试通过使用keycloak来启动keycloak示例,而我使用的合成文件位于我从中获取该文件的下方
https://github.com/keycloak/keycloak-containers/blob/main/docker-compose-examples/keycloak-postgres.yml


# keycloak dependencies

  postgres-keycloak:
    image: postgres
    volumes:
      - postgres_data:/var/lib/postgresql/data
    environment:
      POSTGRES_DB: keycloak
      POSTGRES_USER: keycloak
      POSTGRES_PASSWORD: password
  keycloak:
    image: quay.io/keycloak/keycloak:legacy
    environment:
      DB_VENDOR: POSTGRES
      DB_ADDR: postgres
      DB_DATABASE: keycloak
      DB_USER: keycloak
      DB_SCHEMA: public
      DB_PASSWORD: password
      KEYCLOAK_USER: admin
      KEYCLOAK_PASSWORD: admin
      # Uncomment the line below if you want to specify JDBC parameters. The parameter below is just an example, and it shouldn't be used in production without knowledge. It is highly recommended that you read the PostgreSQL JDBC driver documentation in order to use it.
      #JDBC_PARAMS: "ssl=true"
    ports:
      - 8082:8082
    depends_on:
      - postgres-keycloak

volumes:
  postgres_data:
    driver: local

当我运行该文件时,我得到如下连接错误:

backend_services-keycloak-1           | Caused by: javax.resource.ResourceException: IJ031084: Unable to create connection
backend_services-keycloak-1           | Caused by: org.postgresql.util.PSQLException: FATAL: password authentication failed for user "keycloak"
backend_services-keycloak-1           | 08:53:53,533 FATAL [org.keycloak.services] (ServerService Thread Pool -- 68) Error during startup: java.lang.RuntimeException: Failed to connect to database
backend_services-keycloak-1           | Caused by: javax.resource.ResourceException: IJ000453: Unable to get managed connection for java:jboss/datasources/KeycloakDS
backend_services-keycloak-1           | 08:53:54,449 ERROR [org.jboss.as.controller.management-operation] (Controller Boot Thread) WFLYCTL0013: Operation ("add") failed - address: ([("subsystem" => "metrics")]): java.lang.NullPointerException
backend_services-keycloak-1           | 08:53:54,460 ERROR [org.jboss.as.server] (ServerService Thread Pool -- 45) WFLYSRV0022: Deploy of deployment "keycloak-server.war" was rolled back with no failure message
xzlaal3s

xzlaal3s1#

这个docker-compose.yml将工作。你做错了两个地方(DB_ADDR和端口转发)

version: '3'

services:
  postgres-keycloak:
    image: postgres
    volumes:
      - postgres_data:/var/lib/postgresql/data
    environment:
      POSTGRES_DB: keycloak
      POSTGRES_USER: keycloak
      POSTGRES_PASSWORD: password
  keycloak:
    image: quay.io/keycloak/keycloak:legacy
    environment:
      DB_VENDOR: POSTGRES
      DB_ADDR: postgres-keycloak
      DB_DATABASE: keycloak
      DB_USER: keycloak
      DB_SCHEMA: public
      DB_PASSWORD: password
      KEYCLOAK_USER: admin
      KEYCLOAK_PASSWORD: admin
      # Uncomment the line below if you want to specify JDBC parameters. The parameter below is just an example, and it shouldn't be used in production without knowledge. It is highly recommended that you read the PostgreSQL JDBC driver documentation in order to use it.
      #JDBC_PARAMS: "ssl=true"
    ports:
      - 8082:8080
    depends_on:
      - postgres-keycloak

volumes:
  postgres_data:
    driver: local

并打开URL

http://localhost:8082/auth/

点击此处然后凭证admin/admin(ID /密码)x1c 0d1x

von4xj4u

von4xj4u2#

如果需要,您可以尝试此操作,应用程序名为test
数据库登录名为,keycloak:password
keycloak管理员登录名为:root:root
这将通过web浏览器访问localhost:8080

version: "3.8"
name: test
services:
    keycloak:
        image: jboss/keycloak:15.0.2
        environment:
            DB_VENDOR: POSTGRES
            DB_ADDR: postgres
            DB_DATABASE: keycloak
            DB_USER: keycloak
            DB_SCHEMA: public
            DB_PASSWORD: password
            KEYCLOAK_USER: root
            KEYCLOAK_PASSWORD: root
            KEYCLOAK_HOSTNAME: keycloak
            # Uncomment the line below if you want to specify JDBC parameters. The parameter below is just an example, and it shouldn't be used in production without knowledge. It is highly recommended that you read the PostgreSQL JDBC driver documentation in order to use it.
            #JDBC_PARAMS: "ssl=true"
        ports:
            - 8080:8080
        depends_on:
            - postgres   
        networks:
            - test

    postgres:
        image: postgres
        volumes:
            - postgres_data:/var/lib/postgresql/data
        environment:
            POSTGRES_DB: keycloak
            POSTGRES_USER: keycloak
            POSTGRES_PASSWORD: password
        networks:
            - test    

volumes:
  postgres_data:
      driver: local  

networks:
  test:
    driver: bridge

相关问题