dockerbuilddockerfilekeycloak

Keykloack docker enable features


I'm having trouble enabling certain features in my custom Keycloak Docker image—specifically scripts, impersonation, and passkeys. Despite following the recommended steps, these features aren't available in the final image.What I've done:

A simplified version od my Dockerfile:


# Stage 1: Building Keycloak with features
FROM quay.io/keycloak/keycloak:${KEYCLOAK_VERSION} AS builder
ENV KC_FEATURES=scripts,impersonation,passkeys
RUN /opt/keycloak/bin/kc.sh build

# Stage 2: Final image
FROM quay.io/keycloak/keycloak:${KEYCLOAK_VERSION}
COPY --from=builder /opt/keycloak/providers/ /opt/keycloak/providers/

CMD ["/opt/keycloak/bin/kc.sh", "start", "--optimized", "--cache=ispn", "--verbose"]

The Issue:

Has anyone encountered this issue or knows how to properly include these features in the final image?


Solution

  • /opt/keycloak/providers/ is the path for custom providers (JAR files), and the /opt/keycloak/lib/quarkus/ path is the directory that contains the stuff after the build, therefore

    # Stage 1: Building Keycloak with features
    FROM quay.io/keycloak/keycloak:${KEYCLOAK_VERSION} AS builder
    
    # If you have custom providers
    COPY /service-providers-jars /opt/keycloak/providers/ 
    
    ENV KC_FEATURES=scripts,impersonation,passkeys
    RUN /opt/keycloak/bin/kc.sh build
    
    # Stage 2: Final image
    FROM quay.io/keycloak/keycloak:${KEYCLOAK_VERSION}
    # copy the whole /opt/keycloak/
    COPY --from=builder /opt/keycloak/ /opt/keycloak/
    
    CMD ["/opt/keycloak/bin/kc.sh", "start", "--optimized", "--cache=ispn", "--verbose"]
    

    Or if you want, the COPY line can be in the for of

    COPY --from=builder /opt/keycloak/providers/ /opt/keycloak/providers/
    COPY --from=builder /opt/keycloak/lib/quarkus/ /opt/keycloak/lib/quarkus/