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.jardbk-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:8180dbk-core | Caused by: java.net.ConnectException: Connection refuseddbk-core | at java.base/sun.nio.ch.SocketChannelImpl.checkConnect(Native Method)
My docker-compose.yml
services:database:build: context: ./db-init dockerfile: Dockerfile.dbcontainer_name: dbk-databaseports:- 5432:5432volumes:- "$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: - databasecore: 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/dbkquarkus.oidc.client-id=dbk-corequarkus.oidc.credentials.secret=3a17e7e8-0099-49d9-8e33-d0eb954daba0quarkus.datasource.db-kind = postgresqlquarkus.datasource.username = corequarkus.datasource.password = corequarkus.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.