Running Keycloak in Docker for production

Moving Keycloak from start-dev to a production container means building an optimized image, moving database and hostname settings into environment variables, and planning admin bootstrap, health checks and upgrades by image tag.

On this page

Running Keycloak in Docker for production: what changes from start-dev

A production Keycloak container differs from the one you tested with start-dev in three ways: it runs a pre-built optimized image created with kc.sh build, it starts with start --optimized, and it connects to a supported external database and a fixed public hostname through configuration rather than defaults. Start-dev is meant for local development. It uses an embedded dev-file database, which the Keycloak database guide says is for development only, and it skips the hostname and TLS settings that production needs. Keycloak is an open source identity and access management server licensed under Apache 2.0. It supports the OpenID Connect, OAuth 2.0 and SAML 2.0 protocols, and provides single sign-on, identity brokering, user federation and an admin console. Teams need this work once an application, user population or partner depends on Keycloak for sign-in, even if only one realm and a handful of clients exist.

The first decision is the database. Keycloak lists MariaDB, Microsoft SQL Server, MySQL, Oracle Database, PostgreSQL (14 to 18), EnterpriseDB Advanced, Amazon Aurora PostgreSQL and Azure SQL as supported production options. Confirm the exact version your platform team will operate against the database guide, then set the connection through environment variables such as KC_DB, KC_DB_URL and KC_DB_USERNAME, with the password supplied from a secret rather than an image layer. The second decision is the public hostname, set through KC_HOSTNAME, because tokens, redirects and metadata all depend on it. Confirm which DNS names and TLS certificates the proxy will present before the first start, since changing them later affects every registered client.

Which container settings fit which production choice

This table compares the Keycloak container settings that matter most when moving from start-dev to production, showing when each choice fits and what it trades off. Read each row as a decision: find the production concern you have, then check the option and its cost. Confirm exact keys against the Keycloak version you run, because option names change across releases.

Setting areaWhen it fitsTrade-off to plan for
Build-time options (kc.sh build)Fixed choices such as database vendor, health and metrics support, and enabled features that should not change per container startChanging a build option means rebuilding the image, so each change needs a new image tag and a test run
Runtime options (start --optimized)Values that differ per environment, such as database URL, credentials and hostname, passed as environment variables or flags at startSettings applied at runtime are easier to vary but can drift from the build if teams do not record them together
Database vendor and connection variablesA supported production database such as PostgreSQL, selected at build time and configured with connection settings at runtimeThe dev-file database is for development only; the driver and vendor must match what the image was built with
Hostname v2 settingsPublic frontend URL set once, with a separate admin hostname where the admin console should not share the public addressA wrong hostname breaks redirects and token issuer checks, so test login from every public URL before go-live
Proxy and TLS handlingTLS on all communication with a reverse proxy in front, passing forwarded headers only from trusted addressesMisconfigured proxy headers cause mixed-content errors and incorrect client redirects, and certificate changes need a restart plan
Metrics on the management interfaceEnabling Prometheus metrics at /metrics on the management interface when monitoring is requiredThe management endpoint must stay off the public network, and histogram options add load and series volume
Admin bootstrapCreating the first administrator once through environment variables or the bootstrap command, then managing admins in the consoleLeaving bootstrap credentials in environment files or shell history is a common finding; remove them after first use and confirm the procedure for your version

Database and hostname settings through environment variables

Keycloak stores realms, users, clients and sessions in a relational database, so the database is the first group of variables to set when moving a container off development defaults. KC_DB selects the vendor, and KC_DB_URL, KC_DB_USERNAME and KC_DB_PASSWORD point the server at the instance. The default dev-file database is for development only and cannot be used in production.

  • Supported vendors: The database guide lists MariaDB, Microsoft SQL Server, MySQL, Oracle Database, PostgreSQL 14 to 18, EnterpriseDB Advanced, Amazon Aurora PostgreSQL and Azure SQL as supported production options.
  • Driver fit: Confirm which JDBC driver your image includes for the chosen vendor, because some drivers, including Oracle, are not bundled.
  • Credential handling: Inject the password from your secret manager and confirm which file-based options your image version supports, instead of storing it in a compose file under source control.
  • Schema migration: Keycloak migrates the schema at startup by default, and manual migration is available for large deployments where a DBA reviews the SQL first.
  • Replication: High availability designs require a synchronously replicated database, so the replication topology belongs in the same review as these variables.

Check that the database version appears on the supported list for your Keycloak release and that the database account has the privileges the first migration needs.

Setup sequence from a dev container to a production container

This sequence moves a Keycloak container from the start-dev convenience mode to an optimized production image backed by an external database, behind TLS and a reverse proxy, with a first admin that has no default credentials. Each step ends with a check you can run before moving on.

  1. Provision a supported external database

    Create a production database on one of Keycloak's supported engines, such as PostgreSQL within the supported version range, with a dedicated database user that owns only the Keycloak schema. The dev-file database is for development only, so it cannot be used here. Confirm the exact version range and driver requirements against the Keycloak database guide before provisioning. Done means you can open a connection from the host or network where Keycloak will run, using the new credentials, and the database accepts the connection without the superuser account.

  2. Build the optimized image with kc.sh build

    Run the build step so Keycloak fixes its database vendor and other build-time options into the image, which makes startup faster and lets the server start with start --optimized. Build-time settings such as the database type must be set during this step, not at runtime, so pass them as build arguments or in the build environment. Done means the build finishes without errors and the image starts with start --optimized in a test run, producing a log line that confirms the expected database vendor.

  3. Set database and hostname variables

    Supply runtime settings as environment variables: the database URL, username and password (ideally from a secret store rather than plain text), the public hostname, and the separate admin hostname or path if you plan to expose the admin console differently from public frontend URLs. Keep the proxy and TLS settings in the same configuration set so they can be reviewed together. Done means the container starts, connects to the database and logs the configured hostname without falling back to localhost or a development default.

  4. Place TLS and a reverse proxy in front

    Terminate TLS on all client traffic, either at the proxy or through Keycloak's own TLS configuration, and place a reverse proxy in front of the container. Configure the proxy to forward only the public paths, block the admin console and Administration REST API from public routes, and pass the forwarded headers Keycloak needs for correct URLs. Your network or security team should own the certificate. Done means an external request to the admin path is refused at the proxy, while the public login path returns the expected response over HTTPS.

  5. Bootstrap the first admin without default credentials

    Create the first administrator with the bootstrap mechanism in your Keycloak version instead of relying on the dev-mode default account, and give it a strong, unique password stored in your secret manager. Use a named administrator account rather than a shared login, then plan to remove or disable any temporary bootstrap credential once a permanent admin exists. Confirm the bootstrap command and variable names in the current server guide for your release. Done means you can sign in to the admin console on the admin hostname, and a login with the old default username and password fails.

  6. Start with start --optimized

    Launch the container with the start --optimized command using the image built earlier, so runtime startup uses the prebuilt configuration and does not repeat build-time work. Keep the container's health and metrics settings enabled for the next step, and check the startup log for schema migration messages on first run. Done means the container reaches a running state, the log shows the database connection and migration result without errors, and no development-mode warning appears.

  7. Verify health and metrics endpoints

    Query the health endpoints on the management interface, and if you enabled metrics, query the Prometheus-format metrics endpoint at /metrics on that same interface. Keep these management endpoints off public routes, and confirm that your monitoring system can reach them from inside the network. Done means the health check reports the service as up, and the metrics endpoint returns Prometheus text output that includes Keycloak's own counters, which you can then scrape from your monitoring server.

How the container, database, proxy and admin path fit together

The diagram starts with users and applications sending TLS traffic to a reverse proxy, which forwards public frontend requests to the Keycloak container. The admin console and Administration REST API are reached on a separate hostname or path that the proxy restricts. Keycloak talks to the external database, and the management interface serves health and /metrics only to monitoring. Check that the admin path never shares a hostname with public frontend URLs and that the management port stays off the public network.

Request paths, trust boundaries and the separate admin and management routes.

Security settings to review before the first production start

Keycloak's production guide sets the baseline: encrypted traffic, separated admin and public hostnames, a restricted management surface, and credentials kept out of the image and out of plain configuration. Each card below is one setting to confirm in your container definitions and network layout before the first production start.

TLS on all communication

The production guide calls for TLS on all communication, not only at the edge. Check whether traffic from the reverse proxy to the Keycloak container is encrypted, whether the database connection uses TLS, and whether any internal client that calls Keycloak's backchannel endpoints verifies the certificate. Confirm the certificate chain is trusted by every client and that the keystore is mounted from a secret rather than baked into the image.

Keycloak production guide

Separate admin and public hostnames

Expose the admin console and the Administration REST API on a hostname or context path that differs from the public frontend URL used by end users and applications. In the container, this is set through the hostname settings in environment variables. Verify that the public hostname does not route admin paths, and that your proxy blocks admin paths on the public host entirely.

Limit the management interface

Keycloak serves health and metrics endpoints on a management interface, separate from the main HTTP port. Confirm that the management port is reachable only from your orchestrator, monitoring network, or load balancer health checks, and not from the public network. A container port published to the host or to a public load balancer exposes these endpoints to anyone who can reach that address.

Keep secrets out of plain configuration

Database passwords, the bootstrap admin password, and keystore passwords should arrive from a secret store or a file-based secret mount, not as literal values in a compose file, a Dockerfile, or shell history. Review your docker run commands and container definitions for values set directly in environment variables, and confirm that image layers and build logs contain no credentials.

Remove bootstrap admin credentials

The initial admin account created at first start is meant as a one-time bootstrap. Once a permanent administrator exists with multi-factor authentication enabled, remove the bootstrap environment variables from the running configuration and delete any record of the initial password. Confirm that the bootstrap account is disabled or removed, and that someone other than the operator who created it can recover administrative access.

Restrict metrics exposure

Metrics are exposed in Prometheus format at the management endpoint when metrics are enabled. Metrics can reveal user counts, client names, and cache behavior, so confirm that only your Prometheus scraper can reach the endpoint, and that the scrape path is authenticated or network-restricted. Decide whether HTTP request and cache histograms are needed in production before turning them on.

Upgrading Keycloak by image tag without surprises

Pin every production Keycloak container to an explicit version tag, such as the release you have tested, and never run a floating tag like latest. A floating tag changes what runs on your next restart or pull, so an upgrade happens without a change request, a test run or a rollback plan. The upgrade becomes a deliberate change when the tag in your Compose file, Kubernetes manifest or deployment pipeline is edited, reviewed and promoted through your test environment first. Keep the same pinned image in development, test and production, and record which tag each environment runs so that a rollback has a known target.

Keycloak ships four minor releases a year under the 26.x line, and the project states that breaking changes in a minor release will be opt-in, as set out in its October 2024 release-updates post. That policy lowers the risk of a minor upgrade but does not remove the need to read each release's upgrade notes. Schema migration runs automatically at startup by default. For large databases, the upgrading guide suggests applying the migration SQL manually, so a database administrator can review and schedule it. Decide which path applies to you before the first upgrade, and confirm with your database team how long the migration takes on a copy of production data.

Treat the 26.8 upgrade notes as a test list rather than background reading. Confirm that your outbound mail relay accepts StartTLS enforced without plaintext fallback, because mail that worked before may now fail silently. Check that backchannel logout from external identity providers is signed and that signature validation does not reject tokens your partners send. Expect login failures to be written to the database by default, so review database growth and retention for the audit tables. Also plan the move from the deprecated multi-site feature to the stateless alternative if you use it. Run these checks against a restored copy of your production realm before any production tag changes.

Limits to confirm in your own environment

A Docker image runs Keycloak, but it does not decide whether your database, availability design, orchestration and release choices meet your requirements. The cards below are the points where teams most often assume an answer that their own environment has not confirmed.

Database version and driver

Confirm that your database engine and exact major version appear on Keycloak's supported production list, and that you have the matching JDBC driver. Keycloak supports PostgreSQL 14 to 18 among its listed options, but the dev-file database is for development only. Check whether your organization's own database platform, such as an enterprise PostgreSQL distribution or a managed cloud service, is listed by name before you assume it is covered. Oracle Database is supported, but its driver is not bundled with Keycloak, so you must add it to the image yourself.

Database guide

Single container availability

A single container is a single point of failure for sign-in across every application that depends on it. Before you accept one node, confirm your uptime target, maintenance window and recovery expectations with the business owners. If you need more than one node, plan the high availability architecture first, because both supported multi-site designs depend on a synchronously replicated database. Remember that the database itself also needs its own availability design, which a container image does not provide.

HA overview

Orchestration beyond Docker

Docker Compose or a single host suits a pilot, but production often requires Kubernetes, OpenShift or a virtual machine fleet with its own load balancer, health probes and rolling restarts. Decide which platform your operations team already runs and supports, because the Keycloak Operator, the Helm chart and plain container deployment have different upgrade and configuration paths. Confirm who owns node patching, log collection and certificate renewal on that platform.

Red Hat build or community image

The community image and the Red Hat build of Keycloak come from the same open source project, but they differ in supply, support terms and release cadence. Red Hat's build replaces Red Hat Single Sign-On and is offered with its own subscription. Ask your procurement and security teams which image your support contract, vulnerability process and approved registry require, and confirm that the image you pull is the one your change control approved.

Red Hat build page

Target release and support window

Confirm which Keycloak release you will deploy and whether it matches the current release, 26.8.1, or a version your distribution supports. Upgrades are planned by image tag, and the 26.8 upgrade notes include changes that affect mail, logout token validation and login failure storage. Record the tag you pin, the release notes you reviewed and the date you last tested the upgrade path in a non-production environment.

Upgrading guide

Questions teams ask before running Keycloak in Docker in production

What does running Keycloak in Docker in production cost, and what drives the effort?

The cost is mostly labor: planning, building the optimized image, wiring the database, hostname, proxy and TLS, testing, and handing over runbooks. Costs are one-time for the first production build and recurring for upgrades, monitoring and patching. The main drivers are the target environment (cloud, data center or restricted network), the database choice, how many reverse proxy and hostname layers exist, the number of realms and upstream identity providers, how often you upgrade, and how much testing your change process requires. No DeployOpen price is stated here. Ask any partner, including DeployOpen, for a written scope that lists each of these drivers and separates one-time work from retainer or support work.

Can an internal team run Keycloak in Docker in production without a partner?

Yes, many teams do, provided they have people who can operate a Linux container host, a supported production database, TLS certificates, a reverse proxy and an identity system with its own security model. The Keycloak production guide asks for TLS on all communication, a proxy with path restrictions, and a separate hostname or context path for the admin console and Administration REST API. Check whether your team can own those pieces, run the health and metrics endpoints, and apply upgrades on a planned cadence. If one of those gaps exists, a fixed-scope engagement can close it with documented handover.

How long does a first production Keycloak container take to deploy?

Duration depends on scope, so treat any number you hear as unverified until it appears in a written plan. The main variables are how many environments you need (development, test and production), whether the database and certificates already exist, how much hostname and proxy work is required, how many realms and identity providers must be configured, and how long your change approvals take. Ask the implementer for a dated plan with milestones, the client inputs each milestone needs, and the acceptance tests that close the work. DeployOpen plans engagements this way, with scope, deliverables and timelines agreed in writing before work starts.

What does the work need from our organization before it starts?

Plan access and decisions before the build starts. Typical inputs are:

  • Accounts or hosts where the container runs, with network paths to the database and identity sources
  • A supported production database, such as PostgreSQL, with credentials and a backup owner
  • DNS records for the public hostname and a separate admin hostname or path
  • TLS certificates and trust chains for the proxy and any internal backchannel calls
  • Change windows for test and production cutovers and an approver for each
  • A named owner for admin bootstrap credentials and secret storage

Confirm each item with your infrastructure, security and networking teams early, because DNS and certificate lead times often set the schedule.

Is Docker the right host for Keycloak, or should we use Kubernetes or OpenShift?

Docker on a single managed host can be the right choice for a smaller footprint, but it puts more availability work on your team. Keycloak documents three high availability architectures, and each supported design needs a synchronously replicated database. Kubernetes or OpenShift give you scheduling, rolling restarts and the Keycloak Operator, which is installed through Operator Lifecycle Manager and manages Keycloak custom resources. Choose based on your existing platform skills, required uptime, number of nodes, and how you manage configuration. If you already run a cluster, the Operator path is often easier to govern. Your choice should follow a written decision, not habit.

How are Keycloak upgrades handled when we run it in a container?

Upgrades follow image tags. You build a new optimized image for the target release, test it against a copy of production configuration and data, and then deploy it. Keycloak migrates its database schema automatically at startup by default, and it also supports manual migration, which the upgrading guide suggests for large deployments. The project plans four minor releases a year and a major release every two to three years, and says breaking changes in a minor release will be opt-in. Read the upgrade notes for every version you skip. For example, the 26.8 notes include enforced SMTP StartTLS and mandatory signature validation of backchannel logout tokens from external providers, so test those paths before rollout.

Who is responsible for security and compliance evidence after go-live?

Your organization owns the controls and the evidence, and an independent auditor or certification body issues any audit result. DeployOpen prepares systems, controls and evidence for compliance assessments, but it does not issue audit reports, attestations or certifications. For Keycloak, the evidence usually covers TLS configuration, admin access restrictions, database backup records, patch history, metrics and log retention, and change records for each upgrade. Ask the implementer to name which artifacts they will deliver and which ones your team must keep running after handover.

How DeployOpen scopes and delivers a production Keycloak container

DeployOpen starts every Keycloak container engagement with a written fixed scope, agreed before any work begins. For this topic, the scope names the image build path (the optimized image produced by kc.sh build and started with start --optimized), the target database, the public frontend hostname, the separate admin hostname, the reverse proxy, the TLS certificates, the identity providers and applications that will sign in through the server, and the monitoring endpoints to be exposed. The inventory step matters most. Before writing any configuration, DeployOpen and the client's team list every database instance and its supported version, every hostname and certificate chain, every outbound dependency such as SMTP relays and upstream identity providers, and every realm and client that must exist on day one. Gaps found at this stage, such as a database that is not on the supported list in the Keycloak database guide or an SMTP server that cannot meet the StartTLS requirement in the 26.8 upgrade notes, change the scope and the schedule before they become production incidents. The client should confirm the database engine and version, the certificate authority, and who owns DNS records for each hostname.

Delivery happens inside the client's own infrastructure: their cloud accounts, data center hosts, or private container platform. DeployOpen does not host the running service. Work is performed in the client's environment through access the client grants and revokes, with secrets for the database, the bootstrap admin and the SMTP account stored in the client's secret store rather than in the image or in shared files. Configuration is kept in version control so each change can be reviewed and reproduced. Acceptance checks are agreed in the scope and typically cover a health endpoint response, a successful admin login through the separate admin hostname, a test login through one application, metrics scraped from the management interface, and a restart that completes the database schema step without manual action. The client should ask who holds the bootstrap admin credentials after handover and how they are rotated.

At handover, DeployOpen delivers documentation that the client's own team can operate: the image build procedure, the environment variable inventory, the reverse proxy and hostname settings, the database and backup configuration, the upgrade runbook for moving between image tags, and the list of open items with owners. Ongoing work is optional. Upgrades, security patches and continuous testing can be covered under a retainer, which DeployOpen agrees in writing as a separate scope, because each new Keycloak release can change settings, database migrations and breaking-change behavior that needs review. Quotes should separate one-time build and deployment work from any recurring retainer, and should state which upgrade and testing activities the retainer includes.

How DeployOpen delivers Keycloak in production

DeployOpen plans, implements, hardens, documents and supports self-hosted Keycloak inside your own cloud accounts, data centers or air-gapped networks. For a Docker production deployment, the work starts with a written scope that names the database, hostnames, proxy and admin access model before any container is built.

How we scope

  • Agree in writing which database, hostnames, TLS setup and reverse proxy the Keycloak container will use.
  • Confirm the Keycloak release line and the upgrade-by-image-tag process your team will follow.
  • Define admin bootstrap, separate admin hostname and who can reach the management interface.

How we build

  • Build an optimized image with kc.sh build and start it with start --optimized in your environment.
  • Set database, hostname and proxy settings through environment variables, then test them against your real network paths.
  • Wire health checks and metrics endpoints into your existing monitoring so failures surface before users notice.

How we hand over

  • Deliver the image build files, environment configuration and runbooks in your version control system.
  • Document the upgrade procedure by image tag, including how schema migration runs at startup or manually.
  • Walk your platform and security teams through admin recovery, backups and the checks they should repeat.

How we support

  • Engagements are fixed-scope, with scope, deliverables and timelines agreed in writing before work starts.
  • Ongoing support, upgrades and continuous security testing are available as retainers for your Keycloak estate.
  • Ask for a quote based on the written scope, since DeployOpen does not publish a price list.

Sources and further reading

Talk to our team.

Tell us what you're working on, whether it's a deployment, an audit, a security test or a cyber range. You'll speak with an engineer who can help you scope it.

  • 30-minute call: free, with no obligation.
  • NDA on request: we can sign before you share details.
  • Clear next steps: a scope and plan after the call.