I am running docker desktop (windows) and building docker image for keycloak 17.0.0 following the instructions at here. Build completes successfully but when I run this image in desktop I get error
ERROR [org.key.qua.run.cli.ExecutionExceptionHandler] (main) ERROR:
Failed to obtain JDBC connectionERROR [org.key.qua.run.cli.ExecutionExceptionHandler] (main) ERROR: No
suitable driver found for jdbc:postgresql://postgres/keycloak
postgres is already running in docker desktop with the name "postgres" on default port 5432 and has keyclock database created.
Here is my Dockerfile:
FROM quay.io/keycloak/keycloak-x:latest as builder
ENV KC_METRICS_ENABLED=true
ENV KC_FEATURES=token-exchange
ENV KC_DB=postgres
RUN /opt/keycloak/bin/kc.sh build
FROM quay.io/keycloak/keycloak-x:latest
COPY --from=builder /opt/keycloak/lib/quarkus/ /opt/keycloak/lib/quarkus/
WORKDIR /opt/keycloak
RUN keytool -genkeypair -storepass password -storetype PKCS12 -keyalg RSA -keysize 2048 -dname "CN=server" -alias server -ext "SAN:c=DNS:localhost,IP:127.0.0.1" -keystore conf/server.keystore
ENV KEYCLOAK_ADMIN=admin
ENV KEYCLOAK_ADMIN_PASSWORD=admin
ENV KC_DB_URL='jdbc:postgresql://postgres/keycloak'
ENV KC_DB_USERNAME=postgres
ENV KC_DB_PASSWORD=postgres
ENV KC_HOSTNAME=localhost:8443
ENTRYPOINT ["/opt/keycloak/bin/kc.sh", "start"]
My understanding from the docs is, after setting "KC_DB=postgres", the build should have included postgres driver that appears to be missing.
Can somebody tell me what is wrong here? Thanks.
3
Answers
I guess
KC_DB
is a runtime configuration. See build help:So it should be build parameter
--db=postgres
.BTW: I would use
quay.io/keycloak/keycloak:17.0.0
image (17.0.0 is first stable Quarkus based Keycloak release).I battled with this issue for a while. As Jan Garaj has mentioned
--db=postgres
is a runtime config. So changing the ENTRYPOINT to this fixed the issue for me:And the following if you need to run for production with
"start"
:It is also worth mentioning that the same Dockerfile works with
quay.io/keycloak/keycloak:latest
. I switched the image and foundkeycloak
to be more stable compared to thekeycloak-x
.As Jan Garaj and omufeed already stated, it is a runtime configuration. So the example Dockerfile is wrong. Move the
ENV KC_DB=postgres
to the secondFROM
section so i looks likeSo you don’t have to modify the
ENTRYPOINT
and also can provide those environment variables in a docker compose file.