ERROR OIDC server is not available at the 'quarkus.oidc.auth-server-url' URL when starting quarkus with docker

huangapple go评论80阅读模式
英文:

ERROR OIDC server is not available at the 'quarkus.oidc.auth-server-url' URL when starting quarkus with docker

问题

以下是您提供的内容的翻译部分:

我在使用 Quarkus 和 Keycloak 在 Docker Compose 中时遇到了一个非常令人困惑的问题。当我设置环境变量以覆盖开发配置,即 quarkus.oidc.auth-server-urlquarkus.datasource.jdbc.url,然后尝试运行 docker-compose 文件时,会出现错误消息。它说我的 auth-server-url 不正确,但我在我的 auth-server-url 中没有看到拼写错误或错误。

错误消息:

dbk-core    | exec java -Dquarkus.http.host=0.0.0.0 -Djava.util.logging.manager=org.jboss.logmanager.LogManager -XX:+ExitOnOutOfMemoryError -cp . -jar /deployments/app.jar
dbk-core    | __  ____  __  _____   ___  __ ____  ______ 
dbk-core    |  --/ __ \/ / / / _ | / _ \/ //_/ / / / __/ 
dbk-core    |  -/ /_/ / /_/ / __ |/ , _/ ,< / /_/ /\ \   
dbk-core    | --\___\_\____/_/ |_/_/|_/_/|_|\____/___/   
dbk-core    | 11:32:08 ERROR [io.qu.application] (main) Failed to start application (with profile prod): io.quarkus.oidc.OIDCException: OIDC server is not available at the 'quarkus.oidc.auth-server-url' URL. Please make sure it is correct. Note it has to end with a realm value if you work with Keycloak, for example: 'https://localhost:8180/auth/realms/quarkus'
..........
dbk-core    |   at io.netty.util.concurrent.FastThreadLocalRunnable.run(FastThreadLocalRunnable.java:30)
dbk-core    |   at java.base/java.lang.Thread.run(Thread.java:834)
dbk-core    | Caused by: io.netty.channel.AbstractChannel$AnnotatedConnectException: Connection refused: keycloak/172.24.0.3:8180
dbk-core    | Caused by: java.net.ConnectException: Connection refused
dbk-core    |   at java.base/sun.nio.ch.SocketChannelImpl.checkConnect(Native Method)

我的 docker-compose.yml:

services:
  database:
    build:
      context: ./db-init
      dockerfile: Dockerfile.db
    container_name: dbk-database
    ports:
      - 5432:5432
    volumes:
      - "$HOME/databases/postgres:/var/lib/postgresql/data"
  keycloak:
    image: quay.io/keycloak/keycloak:latest
    container_name: dbk-keycloak
    environment:
      DB_VENDOR: POSTGRES
      DB_ADDR: database
      DB_DATABASE: keycloak_database
      DB_USER: keycloak
      DB_SCHEMA: public
      DB_PASSWORD: keycloak
      KEYCLOAK_USER: admin
      KEYCLOAK_PASSWORD: admin
    ports:
      - 8180:8080
    depends_on:
      - database
  core:
    image: registry.gitlab.com/baudoku/dbk-core:dev
    container_name: dbk-core
    environment:
      QUARKUS_OIDC_AUTH_SERVER_URL: http://keycloak:8180/auth/realms/dbk
      QUARKUS_DATASOURCE_JDBC_URL: jdbc:postgresql://database:5432/dbk_core_database
    depends_on:
      - database
      - keycloak
    ports:
      - 8080:8080

我的 Quarkus application.properties:

quarkus.oidc.auth-server-url=http://localhost:8180/auth/realms/dbk
quarkus.oidc.client-id=dbk-core
quarkus.oidc.credentials.secret=3a17e7e8-0099-49d9-8e33-d0eb954daba0

quarkus.datasource.db-kind = postgresql
quarkus.datasource.username = core
quarkus.datasource.password = core
quarkus.datasource.jdbc.url = jdbc:postgresql://localhost:5432/dbk_core_database

当我手动使用 Docker 启动 keycloak 服务并且手动使用 ./mvnw quarkus:dev 启动我的 Quarkus 应用时,一切正常运行。

英文:

I have a really confusing problem when I use Quarkus and Keycloak in docker compose. When I set the environment variables to override the dev configuration aka quarkus.oidc.auth-server-url and the quarkus.datasource.jdbc.url and then try to run the docker-compose file an error message appears. It says that my auth-server-url is not correct, but I do not see an typo or a mistake in my auth-server-url.

Error message:

dbk-core    | exec java -Dquarkus.http.host=0.0.0.0 -Djava.util.logging.manager=org.jboss.logmanager.LogManager -XX:+ExitOnOutOfMemoryError -cp . -jar /deployments/app.jar
dbk-core    | __  ____  __  _____   ___  __ ____  ______ 
dbk-core    |  --/ __ \/ / / / _ | / _ \/ //_/ / / / __/ 
dbk-core    |  -/ /_/ / /_/ / __ |/ , _/ ,< / /_/ /\ \   
dbk-core    | --\___\_\____/_/ |_/_/|_/_/|_|\____/___/   
dbk-core    | 11:32:08 ERROR [io.qu.application] (main) Failed to start application (with profile prod): io.quarkus.oidc.OIDCException: OIDC server is not available at the 'quarkus.oidc.auth-server-url' URL. Please make sure it is correct. Note it has to end with a realm value if you work with Keycloak, for example: 'https://localhost:8180/auth/realms/quarkus'
..........
dbk-core    |   at io.netty.util.concurrent.FastThreadLocalRunnable.run(FastThreadLocalRunnable.java:30)
dbk-core    |   at java.base/java.lang.Thread.run(Thread.java:834)
dbk-core    | Caused by: io.netty.channel.AbstractChannel$AnnotatedConnectException: Connection refused: keycloak/172.24.0.3:8180
dbk-core    | Caused by: java.net.ConnectException: Connection refused
dbk-core    |   at java.base/sun.nio.ch.SocketChannelImpl.checkConnect(Native Method)

My docker-compose.yml

services:
database:
build:
   context: ./db-init
   dockerfile: Dockerfile.db
container_name: dbk-database
ports:
- 5432:5432
volumes:
- "$HOME/databases/postgres:/var/lib/postgresql/data"
keycloak:
 image: quay.io/keycloak/keycloak:latest
 container_name: dbk-keycloak
 environment:
  DB_VENDOR: POSTGRES
  DB_ADDR: database
  DB_DATABASE: keycloak_database
  DB_USER: keycloak
  DB_SCHEMA: public
  DB_PASSWORD: keycloak
  KEYCLOAK_USER: admin
  KEYCLOAK_PASSWORD: admin
  ports:
  - 8180:8080
  depends_on:
  - database
core:
 image: registry.gitlab.com/baudoku/dbk-core:dev
 container_name: dbk-core
 environment:
   QUARKUS_OIDC_AUTH_SERVER_URL: http://keycloak:8180/auth/realms/dbk
   QUARKUS_DATASOURCE_JDBC_URL: jdbc:postgresql://database:5432/dbk_core_database
 depends_on:
 - database
 - keycloak
 ports:
 - 8080:8080

My Quarkus application.properties:

quarkus.oidc.auth-server-url=http://localhost:8180/auth/realms/dbk
quarkus.oidc.client-id=dbk-core
quarkus.oidc.credentials.secret=3a17e7e8-0099-49d9-8e33-d0eb954daba0

quarkus.datasource.db-kind = postgresql
quarkus.datasource.username = core
quarkus.datasource.password = core
quarkus.datasource.jdbc.url = jdbc:postgresql://localhost:5432/dbk_core_database

When i start the keycloak service with docker and my quarkus application manually with ./mvnw quarkus:dev all is working.

答案1

得分: 3

我自己解决了这个问题 ERROR OIDC server is not available at the 'quarkus.oidc.auth-server-url' URL when starting quarkus with docker。问题出在我的 quarkus.oidc.auth-server-url 上,因为我使用了错误的端口。解决方案是使用 keycloak 服务的内部端口,而不是暴露的端口。

正确的 auth-server-url 是:http://keycloak:8080/auth/realms/dbk

正确的 docker-compose:

core:
 image: registry.gitlab.com/baudoku/dbk-core:dev
 container_name: dbk-core
 environment:
   QUARKUS_HTTP_PORT: 7000
   QUARKUS_OIDC_AUTH_SERVER_URL: http://keycloak:8080/auth/realms/dbk
   QUARKUS_DATASOURCE_JDBC_URL: jdbc:postgresql://database:5432/dbk_core_database
 depends_on:
 - database
 - keycloak
 ports:
 - 8080:7000
英文:

I solved the problem myself ERROR OIDC server is not available at the 'quarkus.oidc.auth-server-url' URL when starting quarkus with docker. The problem was my quarkus.oidc.auth-server-url because I used the wrong port. The solution was to use the inner port of the keycloak service and not the expose port.

The correct auth-server-url is: http://keycloak:8080/auth/realms/dbk

Correct docker-compose:

core:
 image: registry.gitlab.com/baudoku/dbk-core:dev
 container_name: dbk-core
 environment:
   QUARKUS_HTTP_PORT: 7000
   QUARKUS_OIDC_AUTH_SERVER_URL: http://keycloak:8080/auth/realms/dbk
   QUARKUS_DATASOURCE_JDBC_URL: jdbc:postgresql://database:5432/dbk_core_database
 depends_on:
 - database
 - keycloak
 ports:
 - 8080:7000

huangapple
  • 本文由 发表于 2020年9月18日 20:10:25
  • 转载请务必保留本文链接:https://go.coder-hub.com/63955535.html
匿名

发表评论

匿名网友

:?: :razz: :sad: :evil: :!: :smile: :oops: :grin: :eek: :shock: :???: :cool: :lol: :mad: :twisted: :roll: :wink: :idea: :arrow: :neutral: :cry: :mrgreen:

确定