Add how to install extensions to the container docs (#11025)

This commit is contained in:
Andrea Peruffo 2022-04-08 10:56:47 +01:00 committed by GitHub
parent 57f2b744a0
commit 854b75e132
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23

View file

@ -10,8 +10,11 @@ includedOptions="db db-url db-username db-password features hostname https-key-s
Keycloak handles containerized environments such as Kubernetes or OpenShift as first-class citizens. This guide describes how to optimize and run the Keycloak container image to provide the best experience running a Keycloak container.
== Creating an optimized container image
For the best start up of your Keycloak container, build an optimized container image by running the `build` step before starting.
== Creating a customized and optimized container image
The default Keycloak container image ships ready to be configured and optimized.
For the best start up of your Keycloak container, build an image by running the `build` step during the container build.
This step will save time in every subsequent start phase of the container image.
=== Building your optimized Keycloak docker image
The following `Dockerfile` creates a pre-configured Keycloak image that enables the health and metrics endpoints, enables the token exchange feature, and uses a PostgreSQL database.
@ -25,15 +28,15 @@ ENV KC_HEALTH_ENABLED=true
ENV KC_METRICS_ENABLED=true
ENV KC_FEATURES=token-exchange
ENV KC_DB=postgres
# Install custom providers
RUN curl -sL https://github.com/aerogear/keycloak-metrics-spi/releases/download/2.5.3/keycloak-metrics-spi-2.5.3.jar -o /opt/keycloak/providers/keycloak-metrics-spi-2.5.3.jar
RUN /opt/keycloak/bin/kc.sh build
FROM quay.io/keycloak/keycloak:latest
COPY --from=builder /opt/keycloak/lib/quarkus/ /opt/keycloak/lib/quarkus/
COPY --from=builder /opt/keycloak/ /opt/keycloak/
WORKDIR /opt/keycloak
# for demonstration purposes only, please make sure to use proper certificates in production instead
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=change_me
# change these values to point to a running postgres instance
ENV KC_DB_URL=<DBURL>
ENV KC_DB_USERNAME=<DBUSERNAME>
@ -43,12 +46,18 @@ ENTRYPOINT ["/opt/keycloak/bin/kc.sh", "start"]
----
The build process includes multiple stages:
* The `build` command applies options that create an optimized image.
* The files generated by the `build` process are copied into a new image.
* The `build` command applies options and includes custom providers to create an optimized image.
* The files generated by the `build` stage are copied into a new image.
* In this runner image, the specific run configuration is applied. That configuration contains a keystore, the environment-specific hostname configuration, and database configuration.
* In the entrypoint, the `start` command starts the image in production mode.
This example uses a multi-staged build to demonstrate the build and run steps. However, you can also run this process as a single-staged docker build.
This example uses a multi-staged build to demonstrate the build and run steps. However, you can also build a single-staged docker image by removing the following two lines:
[source, dockerfile]
----
FROM quay.io/keycloak/keycloak:latest
COPY --from=builder /opt/keycloak/ /opt/keycloak/
----
=== Building the docker image
To build the actual docker image, run the following command from the directory containing your Dockerfile: