When a custom Keycloak container image is worth building
If you run Keycloak in containers and need a custom provider, a theme, an extra CA certificate or an OS package in the runtime, building your own image is the supported way to add them. The stock image does not contain your code, your branding or your trust anchors, so the question is not whether to build one but whether your needs are large enough to justify owning the build pipeline. Start by listing every addition you need, then sort each one into a category: a provider JAR, a theme directory, a CA certificate for outbound TLS, or an operating system package. Each category has a different place in the image and a different upgrade cost, and that list drives the rest of the design.
The Keycloak container guidance centers on a providers directory that Keycloak reads at build time, a build step that augments the server with those providers and build-time options, and an optimized start that runs the prepared server without repeating the build. Those three pieces are why a custom image is a build artifact rather than a container you patch at runtime. If your only change is a configuration value, such as a hostname or database URL, you do not need a custom image at all, because those settings are supplied at runtime. Confirm the exact directory names, build options and start flags against the Keycloak version you plan to run, since they are version-specific and the upgrade notes may change them.
The stock image is usually enough when you need only standard OIDC, SAML and social brokering, default login pages and a database connection, and when your team has no need to inspect or sign the server's contents beyond what the vendor publishes. A custom image becomes worth building when you need a SPI provider, a branded theme, an internal root CA in the trust store, or a package that the base image lacks, and when your security team needs a reproducible, reviewable artifact. Before committing, ask whether a provider already ships in the release you target, and read the Keycloak server administration guide for the features you plan to use.
How the build stages fit together
The build starts with four kinds of inputs: provider JARs, themes, CA certificates and an OS package list. A UBI stage installs the OS packages, then a Keycloak stage copies in the providers, themes and certificates and runs kc.sh build to fix build-time options. The runtime stage starts the server with start --optimized, and the finished image is signed and pushed to a registry. The customer's cluster or host is the trust boundary, so check what each stage can reach and which keys sign the image.
Stages, inputs and hand-offs from source files to the customer's runtime.
Which customizations go into the image and which stay outside
Custom SPI providers, such as user storage providers, event listeners, authenticators and protocol mappers, are packaged as JAR files and copied into the image's providers directory. Keycloak picks them up during the build step, so any change to a provider means a new image. Providers are compiled against specific Keycloak interfaces, which makes them the customization most likely to break during a version change.
- Build-time discovery: Providers are registered by
kc.sh build, so a changed JAR needs a rebuild and a redeployment, not a configuration edit. - Version coupling: Each JAR depends on the SPI interfaces of the release it targets. Recompile and retest every provider against each new Keycloak release before you adopt it.
- Ownership: Your team, or the partner who wrote the code, owns the source, the build pipeline and the security review for every provider. That work recurs for as long as the provider is in use.
- Third-party JARs: Confirm the license, origin and integrity of any vendor or community provider before it enters the image.
- Upgrade cost: Each Keycloak release requires rebuilding and retesting every provider, so the recurring cost grows with the number of custom providers. Check the upgrading guide for SPI changes in each release.
Before you go live, check that each provider's source, build target and test suite are recorded against one specific Keycloak version.
Themes control the login, account, admin and email pages. They can be baked into the image or supplied when the deployment starts, depending on how your platform is set up. Baking themes in makes every brand change a release, which gives you a tested artifact but adds rebuild work for small visual edits. The decision usually depends on how often the people who own the branding need to make changes.
- Template overrides: Changes to FreeMarker templates depend on the page markup of the Keycloak version in use, so each upgrade needs functional and visual checks on every custom page.
- Separate versioning: Keep the theme in its own repository and release it separately, so a branding change does not force a provider rebuild.
- Email templates: Email pages are part of the theme set. Test them against your mail relay after any SMTP change, including the enforced StartTLS behavior in the 26.8 release.
- Flow and accessibility parity: Confirm that custom pages keep the same authentication steps, translations and accessibility behavior as the defaults, including passkey and OTP screens.
- Upgrade cost: Theme work recurs at each release that changes the templates, and it needs a front-end reviewer and an identity tester, not only a designer.
Before production, check that each theme is assigned to the correct realm or client in a test realm and that every login path renders correctly.
Extra certificates let Keycloak trust internal certificate authorities when it makes outbound calls to LDAP directories, upstream identity providers, SMTP relays or internal APIs. They can be added to a truststore during the build or mounted at runtime and referenced by configuration. Certificates that identify the Keycloak endpoint itself belong in the server keystore, which is a different setting from the truststore, and mixing the two is a common source of TLS errors.
- Rotation schedule: Internal CA and leaf certificates expire on their own timeline. Baking them into the image forces a rebuild at every renewal, so mounting them at runtime is often easier to operate.
- Trust scope: Add only the authorities you need. Each extra root widens the set of certificates Keycloak accepts for outbound connections.
- Keystore and truststore: The certificate that clients see belongs in the server keystore, which you configure through hostname and TLS settings.
- Secrets handling: Truststore and keystore passwords should come from your secret store and stay out of the Dockerfile and image layers.
- Upgrade cost: The cost per release is low, but each renewal needs a deployment. An expired intermediate can break brokering or LDAP sync in ways that appear only under specific flows.
Before cutover, verify chain validation from inside the running container against each internal endpoint Keycloak must reach.
The Keycloak base image is intentionally minimal. If you need a utility for troubleshooting, a font for themes or a native library for a custom provider, install it in a builder stage based on a Red Hat Universal Base Image and copy only the results into the final stage. A multi-stage build keeps compilers and build tools out of the runtime image. Each package install also creates a dependency on the repository it comes from and on that repository's patch cadence.
- Stage separation: Build tools stay in the builder stage. Only the files the runtime needs are copied forward, which keeps the final image smaller and easier to scan.
- Repository access: Builds in restricted networks need a mirrored package repository. Keeping that mirror current is a recurring operational cost.
- Patch cadence: OS packages receive fixes on their own schedule. Plan rebuilds for security updates even when no new Keycloak release has shipped.
- Base image pinning: Pin the UBI tag and record image digests so that a rebuild from the same inputs produces the same result.
- Upgrade cost: A base image change can alter library versions that your providers load, so retest providers after every base image update, not only after Keycloak upgrades.
Before release, confirm the final image runs as the non-root user Keycloak expects and that the package list matches what your image scanner reports.
Settings that vary by environment, such as database address, public hostname, proxy trust, log levels and admin bootstrap, belong outside the image as environment variables or a configuration file. Build-time options, passed to kc.sh build, are fixed into the optimized image and do require a rebuild. Keeping environment-specific values out of the image lets one tested artifact move from test to production unchanged.
- Build-time options: Choices such as the database vendor and enabled features are compiled into the optimized image, so changing them means a new build and a new test cycle.
- Runtime options: Hostnames, database URLs, proxy settings and log levels arrive at start through
KC_variables, so changing them does not require a new image. - Secrets: Pass credentials through your orchestrator's secret mechanism so they never appear in image layers or in shell history.
- Environment promotion: Use one image with a separate set of runtime values per environment. This keeps the artifact your security team reviewed identical across stages.
- Upgrade cost: Option names can change between releases, so review the upgrade notes before each change. The cost per release is small but recurs, and it falls on whoever owns the deployment manifests.
Before each release, compare your build-time and runtime option lists against the production configuration guide for the version you are moving to.
How to build, test and publish the image
This sequence turns a list of providers, themes and certificates into a tested, signed Keycloak image that behaves the same way in every environment that runs it. Each step ends with a check, so a failed provider or missing certificate is caught before the image reaches production.
Inventory every addition before writing code
The platform or identity team lists each provider JAR, theme directory, OS package, truststore certificate and configuration key the image must carry, with its source, version and owner. Record the Keycloak version the image targets, since providers compiled for one minor release may not load on another. Confirm the list against the upgrade notes for that release. Done means every item has a named owner and a source you can reproduce, and nothing is copied in by hand from a running server.
Write a multi-stage Containerfile
The build engineer writes a Containerfile with a build stage that starts from the official Keycloak image and copies in providers and themes, and a final stage that starts from the same base. The UBI stage is used only when an OS package is needed, and that package is installed there and nowhere else. Pin image tags to the exact Keycloak release rather than a floating tag. Done means the file builds without errors on a clean machine and contains no secrets, passwords or private keys.
Run kc.sh build in the build stage
The build stage runs kc.sh build with the same build-time options the target environment uses, such as the database vendor and health or metrics flags. Build-time options are fixed into the image, so a mismatch here means a rebuild, not a restart. Check the build log for the provider lines and for any warning about an unsupported option. Done means the build completes and the optimized server output is generated without errors.
Copy only the runtime output into the final image
The final stage copies the built Keycloak directory and the approved additions from the build stage, leaving compilers, package caches and build tools behind. Compare the final image file list with the inventory from step one to confirm nothing unexpected was carried over. Done means every file in the image traces back to an inventory item or the official base.
Start with --optimized and verify providers load
Start the container with the start --optimized command and the same environment variables the target environment will use, with a test database if needed. Search the server log for each provider name and for any startup error about a missing class or failed provider. Then call the health endpoints and confirm they report ready. Done means every provider from the inventory appears in the log, the health checks succeed and the server reaches its listening state without errors.
Test the image in an environment that matches the target
The team runs the image against a staging realm and database with the same hostname, proxy, TLS and truststore settings as production, then signs in with a test user through each custom theme and provider. Confirm that a federated login, an email send and a certificate-trusting outbound call behave as expected. Done means the test cases in the agreed plan pass and the results are recorded with the image digest.
Tag, sign and publish the image
The release owner tags the image with the Keycloak version and a build identifier, signs it with the organization's signing key, and pushes it to the internal registry. Record the image digest, the Keycloak version and the list of inventory items in the release record. Verify the signature from a machine that will deploy the image. Done means the registry holds the signed image, the signature verifies, and the deployment pipeline references the digest rather than a mutable tag.
Security controls for a custom Keycloak image
A custom Keycloak image carries your providers, themes and certificates into production, so every layer of it is part of the security boundary. The controls below cover how the image is built, what it contains, how it is verified before it runs and where the admin surface is exposed. Each one is a decision your team or your partner should record before the first production build.
Run as a non-root user
The final stage should start Keycloak under an unprivileged user instead of root, so a compromised process cannot easily change system files or the mounted configuration. Confirm the user, its file ownership on the providers directory and the writable paths Keycloak needs at runtime. Check that the base image you extend keeps that user configuration after your changes. Test the running container with the same user your orchestrator enforces, because permission errors often appear only there.
Keep build tools out of the final stage
Compilers, package managers, Maven or Gradle caches and build secrets belong in the builder stage only. The final stage should contain the optimized Keycloak runtime, the providers you chose and the certificates needed at startup. Run kc.sh build in the builder so the final image starts with start --optimized. Review the finished image's file list for leftover source trees, .m2 directories and .env files before each release.
Pin base images by digest
A tag such as a release number can be repointed to different content, so the base image in your Dockerfile should reference an immutable digest. Record which Keycloak version and which UBI base the digest corresponds to, and update the pin deliberately when you rebuild. Ask your platform team how digest updates are reviewed and who approves them. This keeps a rebuild from silently changing the operating system layer under a release you already tested.
Verify provider JAR provenance
Every provider JAR copied into the providers directory is code that runs inside the identity server, so each one needs a known source, a version and a checksum. Store the checksums in version control, fetch artifacts from an internal repository and reject any file whose hash differs from the recorded value. Ask the provider's maintainer whether they publish signatures, and decide who may approve a new provider. Unreviewed providers are one of the most direct paths to compromising login.
Sign images and verify at admission
Signing the image after it passes tests lets the cluster confirm that only approved builds run. Your admission policy should reject unsigned images or images signed by an unknown key, and the signing key should live in a managed key store with restricted access. Confirm which signing tool and admission controller your platform supports, and how signatures are rotated when a key is retired. Signing proves who built the image, not that the image is free of flaws.
Scan and rebuild on each release
Run a vulnerability scan on the base image, the operating system packages and each provider JAR before the image is promoted. Treat findings as inputs to a rebuild, since a fix usually means a new base digest or a new Keycloak release. Keycloak ships four minor releases a year according to the project plan, so a scan-and-rebuild cadence should be part of the operating model from day one. Ask who owns triage and how long a critical finding can stay open.
Separate the admin hostname
The production guide asks for the admin console and Administration REST API to run on a different hostname or context path from public frontend URLs. Configure the reverse proxy to expose only the paths your users need, and block admin paths on the public listener. Your image settings and the proxy routing must agree on these hostnames, or logins and admin access will fail in confusing ways. Test that the admin paths are unreachable from the public network before go-live.
Production guideHow to keep a custom image current across Keycloak releases
Keycloak plans four minor releases a year, so a custom image is never finished. The providers, themes and extra certificates you baked in have to be checked against every new version, because custom SPI providers compile against internal Keycloak APIs that the project can change between releases. Treat each release as a change to your image, not just a tag bump. Before you commit to a version, read the release notes and the upgrade notes for the minor line you are moving to, and confirm which of your providers depend on classes or interfaces that the notes mention. The project's backwards compatibility post explains how breaking changes are introduced in minor releases, which helps you decide how much review each upgrade needs.
Build a rebuild routine that runs the same steps every time. Pull the new base Keycloak release and update the version in your multi-stage Dockerfile. Rebuild the image from a clean context so no stale providers leak in. Run your provider unit and integration tests, then start the image against a copy of production-shaped data and check that your themes render on the login, account and email pages. Run the schema migration check against a restored database snapshot and review the SQL or the startup log, since Keycloak migrates the schema automatically at startup by default. Only then promote the image through test and into production. Record which provider versions and which Keycloak version each image contains, so a rollback is a tag change rather than a rebuild under pressure.
If Keycloak runs on Kubernetes through the Operator, pair the image pipeline with the Operator's manual approval mode for operator updates. The Operator documentation strongly recommends this mode to avoid unintended automatic upgrades, so a new Operator version does not roll your custom image forward before your tests have run. Confirm which Keycloak image version the Operator will deploy, and make the image reference in your Keycloak custom resource point to your own registry tag, not an upstream tag you have not tested. Treat the approval step as the release gate: the image pipeline proves the build works, and the approval decides when the cluster takes it.
Limits to confirm before you commit to a custom image
A custom Keycloak image bundles your providers, themes and certificates into artifacts that must match a specific Keycloak release, base image and deployment path. The cards below cover the checks that decide whether the image can be built, mirrored and deployed in your environment before any build work starts.
Provider support for the target release
Each custom SPI provider, theme or third-party extension is compiled against Keycloak's internal interfaces, so it may fail or behave differently on a new release. Ask the provider's maintainers or vendor which Keycloak versions they test against, and confirm that the release you plan to run is among them. Record the answer in the build plan, because it sets how often you must retest. Confirm this before writing code, not after the image fails to start.
Release update policyBase image and UBI package access
A Dockerfile that installs OS packages through a UBI stage needs repository access at build time. Confirm that the Keycloak base image, the UBI base and the package repositories are reachable from your build network, or that they are mirrored into your internal registry. In air-gapped networks, check that every package dependency is mirrored as well, not just the top-level package. Ask whether your mirror is refreshed on a schedule that matches your patch process.
Database drivers and Oracle
Keycloak does not bundle an Oracle JDBC driver, so an Oracle deployment needs the driver added to the image or the providers directory. Confirm the driver version with Oracle and your Keycloak release, and confirm that your licensing permits redistribution inside an image. Check the same for any other database driver you plan to add, and confirm that the database is on the supported list for your target release.
Keycloak database docsLayout fit with the Operator or OpenShift
The Keycloak Operator and OpenShift deployments expect the image to be referenced in a specific custom resource or deployment spec, and the Operator's update behavior controls when a new image rolls out. Confirm with your platform team whether the Operator reads your image path and whether custom providers must sit in a location the Operator mounts. Also confirm how image pull secrets, certificates and trust stores are supplied in your cluster before you choose the image layout.
Operator installation docsImage signing and registry policy
Your security team may require every image to be signed, scanned and pulled only from an approved registry. Confirm which signing tool and verification point your cluster enforces, and whether your admission controls accept an image built outside the central pipeline. Ask who holds the signing keys, how they are rotated, and whether a rebuild after each Keycloak release needs a new approval. These answers decide whether the build pipeline can ship on your schedule.
Rebuild ownership for each release
A custom image must be rebuilt and retested for every Keycloak release you adopt, including security releases. Confirm who owns that rebuild, who approves it, and how long your change process takes for an image change. Check whether your Operator approval mode allows you to hold upgrades until the custom image passes tests. Without a named owner, custom providers often fall behind and block security updates.
Questions teams ask before building a custom Keycloak image
What drives the cost and effort of building and maintaining a custom Keycloak image?
The cost is mostly labor, split between the one-time build and the recurring rebuild work. The one-time part covers packaging each provider, theme and certificate, writing the multi-stage Dockerfile, setting up the build pipeline and testing the image against a realistic realm. The recurring part is rebuilding, retesting and redeploying every time you move to a new Keycloak release. Costs rise with the number of custom providers, how much each one depends on internal Keycloak APIs, how many environments you run and how strict your signing and evidence requirements are. Ask any quote to itemize the build, the test realms, the pipeline and the per-release rebuild as separate lines.
How long does a first custom Keycloak image build usually take?
The duration depends on what goes into the image, not on the Dockerfile itself. A team that only adds certificates and a theme will finish far sooner than a team that packages several SPI providers, needs OS packages from a UBI stage and must sign the image. The main drivers are how many providers exist and whether their source code is available and buildable, how well they are documented, whether they were written against the Keycloak version you run, and how many environments must be verified before go-live. Ask for a written scope with the deliverables listed, since no fixed timeline can be stated without that inventory.
What must our team provide before a custom image build starts?
Plan to supply five categories of input. First, the source code or build artifacts for every provider and theme, with the Keycloak version each one targets. Second, the extra certificates, such as internal certificate authorities, and who owns their renewal. Third, one or more test realms that resemble production clients, identity providers and flows, so the image can be checked end to end. Fourth, access to your container registry and the signing keys or service you use. Fifth, the network paths the build and runtime need, including any internal package mirrors. Missing any of these usually moves work from build to discovery, so confirm them during scoping.
Can an internal team run a custom Keycloak image without outside help?
Yes, if the team has container build skills, Java experience for the providers and a process for testing login flows after each change. The work is manageable when the custom code is small and well maintained. It becomes harder when the team must read Keycloak source to fix provider breakage, when no one owns the test realms, or when release cycles are not scheduled. A useful test is whether two people on the team can each rebuild the image from the repository, pass the same test suite and explain every layer in it. Where that is not yet true, a partner can build the first version and hand over the pipeline and runbook.
How often must a custom Keycloak image be rebuilt?
Rebuild the image every time you adopt a new Keycloak release you intend to run, and whenever a base image, OS package or provider changes. Keycloak plans four minor releases a year, so the cadence is set by your own patch and upgrade policy rather than by a fixed external schedule. Since Keycloak 26.0 the project says breaking changes in a minor release will be opt-in, which lowers the risk of each rebuild, but every custom provider still needs compiling and testing against the new version. Confirm your rebuild trigger, test gate and rollback method before the first release.
Which parts of a custom Keycloak image should be signed and checked?
Sign the final image and verify the signature before deployment, so the cluster or host only runs images your pipeline produced. The signature protects the image; it does not replace testing the providers inside it. Record which provider versions, certificates and base image digests went into each build, so auditors and incident responders can trace what ran in production. The exact signing tool depends on your registry and policy, so confirm it with your security team and your registry vendor before the design is fixed.
Does the custom image change how Keycloak is upgraded?
It changes the upgrade work in a practical way. Each upgrade now includes rebuilding the image against the new release, checking that every provider still compiles and loads, and running the test realms through login, token and admin flows before rollout. The database migration is separate: Keycloak migrates its schema automatically at startup by default and also supports manual migration, which its upgrading guide suggests for large deployments. Plan both steps together so a failed provider build never leaves a half-upgraded environment in front of users.
Who should own the image pipeline after go-live
The platform or security team should own the base image, the build pipeline and the signing keys, while application teams own the requests for providers and themes that go into it. Those two groups should not share the same approval rights. The platform team decides which base image and Keycloak version are approved, which OS packages are allowed through the UBI stage, and which build passes the checks. Application teams submit a provider or theme with its source, version, the Keycloak release it was built against and the test cases that exercise it. Nobody should be able to push a custom provider straight into a production image without that review, because a provider runs inside the process that authenticates every user.
A second owner is needed for the rebuild. Every Keycloak release, and every base image update, produces a new image that has to be built, tested against the custom providers and redeployed. Name a specific person or role for that work and give it a calendar trigger tied to the release cadence in the Keycloak blog and the upgrade notes for each minor version. Ask your partner or internal team to write down who runs the rebuild when the primary owner is away, and who can stop a release that fails a provider test. If a provider breaks on a new release, the rebuild owner should be able to fall back to the last signed image without waiting for a developer.
The handover at go-live should include the Containerfile with pinned base image digests, a test realm that exercises each custom provider and theme, and a runbook covering build, test, signing, promotion and rollback. The signing keys must be generated and held in your own key management service or hardware-backed store, not in a partner's workspace or a shared build server. Confirm with your team which signing tool and verification method your admission controls will check, and test that an unsigned or altered image is refused in your environment before you rely on it. Ask for a written list of every artifact delivered, the custody of each secret, and who holds administrative access to the build system after the engagement closes.

