One option, several spellings
Keycloak’s Quarkus distribution reads its configuration from several places: the command line, environment variables, and the file conf/keycloak.conf. Every option exists in all three, under a predictable name. The option that sets the database host is db-url-host. On the command line it is --db-url-host=…, in keycloak.conf it is db-url-host=…, and as an environment variable it is KC_DB_URL_HOST.
The rule is simple, yet the spellings drift apart in real projects. A team starts with a kc.sh command in a README, moves to a Compose file with environment variables, and later to a Kubernetes env list. Each move is a chance to drop an option or mistype one. This converter reads options in any of those forms and writes them back in the one you need.
The mapping rule
To get the environment variable from an option name, put KC_ in front, write the name in capitals, and replace each dash with an underscore. To go back, drop KC_, use lower case, and turn underscores into dashes.
| Option | Command line | Environment variable | keycloak.conf |
|---|---|---|---|
db | --db=postgres | KC_DB=postgres | db=postgres |
db-url-host | --db-url-host=postgres | KC_DB_URL_HOST=postgres | db-url-host=postgres |
hostname | --hostname=https://auth.example.com | KC_HOSTNAME=https://auth.example.com | hostname=https://auth.example.com |
proxy-headers | --proxy-headers=xforwarded | KC_PROXY_HEADERS=xforwarded | proxy-headers=xforwarded |
health-enabled | --health-enabled=true | KC_HEALTH_ENABLED=true | health-enabled=true |
The addresses above are made-up samples.
Which source wins
When the same option is set in more than one place, the command line wins over environment variables, and environment variables win over keycloak.conf. That is useful: a container image can ship a keycloak.conf with sensible values, and each environment overrides what differs with variables.
SPI options
Options for individual providers start with spi-. Their names contain the provider’s ids, which can contain dashes themselves. In the environment form, a dash and a separator both become underscores, so the way back from a KC_SPI_… name can be ambiguous. Check a converted SPI option against the provider’s documentation.
Build options and runtime options
Keycloak separates options that shape its optimized build from options read at every start. Build options include db, features, health-enabled and metrics-enabled. Runtime options include the hostname, database URL and credentials.
With plain kc.sh start, Keycloak notices changed build options and rebuilds on its own, which makes the start slower. With kc.sh start --optimized, it skips that check, so you must run kc.sh build after changing a build option. Container images built for fast starts usually run kc.sh build in the Dockerfile and start --optimized at run time.
FROM quay.io/keycloak/keycloak:26.8.1 AS builder
ENV KC_DB=postgres
ENV KC_HEALTH_ENABLED=true
ENV KC_METRICS_ENABLED=true
RUN /opt/keycloak/bin/kc.sh build
FROM quay.io/keycloak/keycloak:26.8.1
COPY --from=builder /opt/keycloak/ /opt/keycloak/
ENTRYPOINT ["/opt/keycloak/bin/kc.sh"]
CMD ["start", "--optimized"]The converter marks the build options it knows about, so you can see which changes need a rebuild.
Values that need care
The option name follows one rule, but values differ in how each format treats them. Most surprises come from three kinds of value.
Lists
Some options take a comma-separated list. features lists preview or optional features to turn on, and log-level takes a default level followed by per-category levels, such as info,org.keycloak:debug. Keep the list as one value. Do not split it across several variables or lines.
Booleans and numbers
Keycloak reads true and false as text. In YAML, an unquoted true or 8080 becomes a boolean or a number, and Kubernetes refuses a non-string env value. The converter writes every YAML value in single quotes so this cannot happen.
Characters the shell cares about
A value with spaces, $, & or quotes needs quoting on the command line and in .env files that a shell reads. The converter quotes such values for the shell. A database password full of symbols is the usual case.
What this tool does and does not do
- It reads a
kc.shcommand line, including--name=value,--name valueand continued lines ending in a backslash. - It reads
KC_variables from.envlines,exportstatements, Compose environment blocks in both map and list form, and Kubernetesname:andvalue:pairs. - It reads
keycloak.conflines and skips comments. - It writes the options as a command line,
.envlines, a Compose environment block, a Kubernetes env list orkeycloak.conf. - It flags names outside its list of common options, build options, secrets written in plain text and SPI options.
- It keeps command flags such as
--optimizedand--import-realmin the command-line form only. - It does not know every option of every version, check values, or read a running server.
How to use it
- Paste what you have: a command, a Compose service’s environment, a Kubernetes env list or a
keycloak.conf. Mixing them in one paste works. - Check the table of options the tool read, with the environment name of each.
- Pick the output format you need and copy it.
- Read the notes. Fix any name the tool did not recognize, and move secrets out of files.
Where it pays off
From a VM to containers
A Keycloak that ran on a VM often keeps its settings in keycloak.conf or a systemd unit with a long command. Paste either, choose the Compose or Kubernetes form, and you have the environment block for the new deployment.
From Compose to Kubernetes
Compose and Kubernetes write environment variables differently. Paste the Compose block and copy the Kubernetes env list. For the Keycloak Operator, most options become fields of the resource and the rest go into additionalOptions under their plain names, which the converter also shows.
Reviewing someone else’s setup
When you inherit a deployment, settings are spread over a Dockerfile, a Compose file and a keycloak.conf. Paste them together to see the full list in one place, and spot an option set twice with different values.
After an upgrade from an older version
Several options were renamed or removed over Keycloak’s recent releases. The hostname options changed in Keycloak 25, for example, and the older proxy modes gave way to proxy-headers. The converter flags names outside its list, which is a quick way to find options to look up in the release notes.
Common errors and how to fix them
Keycloak refuses to start with an unknown option
On the command line Keycloak rejects an option it does not know. Check the spelling with kc.sh start --help, which lists the options of your version.
A setting seems to be ignored
In environment variables and keycloak.conf, a typo is easy to miss. Another source may also override the value, since the command line wins over the environment and the environment over the file. Paste every source together to see the final value.
A change has no effect after restart
If the server starts with --optimized and you changed a build option such as db or health-enabled, run kc.sh build again or rebuild the image.
Quotes end up in the value
Compose and Kubernetes YAML treat quotes as part of the syntax, but a .env file read by another tool may not. The converter quotes values where each format needs it. When you edit by hand, keep values such as true and port numbers quoted in YAML so they stay strings.
Security notes
- Options such as
db-passwordandbootstrap-admin-passwordhold secrets. Keep them in a secret store and inject them as environment variables. - A password on the command line shows up in process lists and shell history.
- In
keycloak.conf,${VAR}reads a value from an environment variable, which keeps the secret out of the file. - Do not paste production secrets into any web page you do not trust. This page converts in your browser and sends nothing, but a placeholder works just as well.
Best practices
- Pick one source of truth per environment, usually environment variables in containers.
- Put build options into the image with
kc.sh build, and keep runtime options outside it. - Keep option names in their plain form in documentation; the environment form follows from the rule.
- Check the release notes for renamed options before an upgrade.
Moving realms to another server as well? The migration page describes how we move them into a managed cluster.