How to create a custom Keycloak container image
Using the Keycloak image template (recommended)
Use the custom-keycloak-image-template Cookiecutter template to generate a project that builds a fully optimized Keycloak image.
The resulting image is used with the customImage field in your VSHNKeycloak claim.
Prerequisites
-
cookiecutter >= 2.0
-
Docker with buildx
Steps
-
Generate a new project from the template.
cookiecutter gh:vshn/custom-keycloak-image-templateAnswer the prompts:
project_name [My Custom Keycloak]: Acme Keycloak project_slug [acme-keycloak]: keycloak_version [26.6.1]: 26.6.1This creates a directory named after your
project_slug. -
Add your themes and provider JARs to the generated project.
cp -r my-theme/ acme-keycloak/themes/ cp my-provider.jar acme-keycloak/extensions/Themes go under
themes/and provider JARs go underextensions/. -
Build the image locally to verify it compiles correctly.
cd acme-keycloak make build -
Push the image to your container registry.
make push IMAGE=ghcr.io/my-org/acme-keycloakThe image is tagged with the Keycloak version by default (e.g.
26.6.1). Override withTAG=<your-tag>if needed. -
Reference the image in your
VSHNKeycloakclaim using thecustomImagefield. See Customization for the full example.
Legacy approach (for use with the deprecated customizationImage field)
This approach uses the deprecated customizationImage field. Use the template-based approach above with the customImage field instead.
|
The legacy approach packages themes and providers into a minimal container image. At pod startup, an init container copies the files into the running Keycloak instance.
-
Open a command line and create two directories.
mkdir themes && mkdir providers -
Place your themes and providers in respective directories.
-
For other custom files and folders, create them as necessary:
mkdir my-folder && touch pw-blacklist.txt -
Create the following Dockerfile.
cat <<EOF >>Dockerfile FROM alpine COPY themes /themes COPY providers /providers # Custom files COPY pw-blacklist.txt /pw-blacklist.txt COPY my-folder /my-folder EOF -
Build your Docker image.
docker build -t myuser/keycloak-custom:v1 . -
Push your image to the registry.