javadockerdocker-composeconfigquarkus

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


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.


Solution

  • I solved the problem myself :). 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