On this page
Short answer
The docker run command in the Keycloak getting-started guide runs development mode (start-dev), which the container guide says should be strictly avoided in production. A production container needs a build step, an explicit hostname, TLS or proxy settings, and an external database.
The docker run command in the Keycloak getting-started guide runs development mode (start-dev), which the container guide says should be strictly avoided in production. A production container needs a build step, an explicit hostname, TLS or proxy settings, and an external database.
A compose file can carry all of that, but it does not make the design production-grade on its own. If you want a second pair of hands on a container deployment, see our Keycloak support page.
Why is start-dev not safe for production?
Keycloak's container guide says start-dev "should be strictly avoided in production environments because it has insecure defaults." Production mode (start) uses only secured HTTPS communication, and it requires settings that dev mode skips, starting with the hostname and the database.
The getting-started page itself lists three things to do before production: switch to a production-ready database such as PostgreSQL, configure SSL with your own certificates, and replace the quick-start admin password. It also gives the admin as an environment-variable pair, KC_BOOTSTRAP_ADMIN_USERNAME and KC_BOOTSTRAP_ADMIN_PASSWORD, because the guide says initial admin creation only works from a local connection, which containers do not provide.
What is the difference between start, start --optimized and build?
kc.sh build bakes build-time options into the image. start --optimized then skips that work. Plain start detects and applies build options at every startup, which the guide says increases startup time and produces a mutable image that is not best practice.
The documented pattern is a two-stage Containerfile: the first stage runs kc.sh build, the second copies /opt/keycloak from it. Custom provider JARs go into /opt/keycloak/providers before the build. The guide also notes that a changed JAR timestamp can make start --optimized fail, with a fixed-date touch before build as the fix.
| Command | Mode | Build work | Use |
|---|---|---|---|
| start-dev | Development | At each start | Local trials only |
| start | Production | At each start | Works, but mutable and slower to start |
| build, then start --optimized | Production | Once, in the image | The pattern the container guide recommends |
Which settings must be set at build time and which at run time?
In the guide's sample, KC_HEALTH_ENABLED, KC_METRICS_ENABLED and KC_DB are build-time options, set before kc.sh build. Database URL, username, password and hostname are runtime options. Changing a build-time option later means building a new image.
The database choice matters here. Keycloak's database guide says the server defaults to the dev-file database, meant only for development, and that in production mode that default is deprecated, so you should name the vendor explicitly. It lists PostgreSQL, MySQL, MariaDB, Oracle and Microsoft SQL Server, each with a tested version. Pool settings are also yours to set; the db-pool-max-size default is 100.
What do hostname and proxy settings break first?
Hostname is where start-dev and start differ most visibly. In production mode you must set either --hostname or --hostname-strict false. In start-dev, hostname-strict defaults to false, so a setup that worked in development fails on the first production start.
Behind a proxy, the reverse proxy guide says to set proxy-headers (forwarded or xforwarded). If you leave it unset when the proxy is not doing TLS passthrough, origin-checking requests return 403 Forbidden. When TLS ends at the proxy, http-enabled must be true. The guide says to expose /realms/, /resources/ and /.well-known/, keep /admin/ internal, and never proxy port 9000, which serves health checks and metrics when enabled.
See the guide's reverse proxy page for the full path list.
What happens to data and volumes in a container?
Anything Keycloak keeps in the container filesystem disappears with the container. The guide says realm import files mounted at /opt/keycloak/data/import with --import-realm "may only make sense to do in Dev mode." For production, the external database is the state, so it needs its own backups.
That also changes how you think about recovery: the container is disposable, the database is not. Our write-up of upgrade and rollback failure modes covers what that means for version changes.
Is a Docker Compose file a production design?
No. A compose file starts containers; it does not decide how many instances run, where the database lives, how traffic is balanced, or who is paged. Keycloak's production guide says a typical production environment contains two or more instances and that the database is crucial to availability and integrity.
The container guide also says to always set a memory limit and recommends 2 GB for smaller production deployments. If you are heading toward Kubernetes, our production setup on Kubernetes guide is the next step, and the cluster and session cache failure modes post covers what multiple nodes add.
When should you call for help?
Call when the container is already serving real logins and something about hostname, proxy headers, the database or an upgrade is failing, or when nobody on the team owns the deployment. AceMQ senior engineers support Keycloak operations on community or Red Hat build installs, 24/7. We do not sell Red Hat subscriptions or advise on their licensing, and defects in Red Hat's build go to Red Hat. See Keycloak consulting for design and review work.
Sources
Frequently Asked Questions
Can I run Keycloak in Docker in production?
Yes. Keycloak publishes container images and documents running them in production. Use start --optimized after a build step, set the hostname, use TLS or documented proxy settings, and connect an external database instead of the default dev-file database.
Why does Keycloak return 403 behind my proxy?
The reverse proxy guide says that if proxy-headers is unset and the proxy is not doing TLS passthrough, origin-checking requests return 403 Forbidden. Set proxy-headers to forwarded or xforwarded, and make sure the proxy overwrites those headers.
Where does Keycloak store data in a container?
In dev mode it uses the dev-file database, which is meant only for development. In production you choose a database vendor with the db option, such as postgres, and the state lives there, not in the container.
Talk to an engineer
Need a hand with Keycloak?
Senior engineers who run it in production. Get a quote or a free consultation, no sales pitch.

