Self-host Keycloak (Postgres) with Levelrail

Keycloak backed by Postgres instead of its default embedded database, for a real multi-instance setup.

  • Authorkeycloak
  • LicenceApache-2.0
  • Memory1 GiB
  • Archarm64
  • Services2

How to self-host Keycloak (Postgres)

  1. Pull the images

    2 images are pulled on your server.

    Show images
    • postgres:16-alpine
    • quay.io/keycloak/keycloak:26.1
  2. Create the app

    2 services start in a single Compose app, with 2 named volume mounts for your data, on port 8080.

  3. Fill in the secrets

    4 secrets are generated and stored encrypted, 10 settings are preset, you do not have to fill in anything.

  4. Open it

    Without a domain the app gets an sslip.io address; add --domain SERVICE=HOST to use your own.

Keycloak (Postgres) requirements

Memory
About 1 GiB
Architectures
amd64 image published, arm64 image published
Ports
8080
Domain
Optional, an sslip.io address is used without one
Settings
none to fill in
License
Apache-2.0, permissive license
  • Listed. It is in the catalog but not verified. Back up the data volume before changing an image tag.
  • Host ports. It publishes port 8080 on the host, so open them in the VPS firewall only if you want that.

Install Levelrail first

On a server with Levelrail running, run the command above, or open the dashboard: Apps, New app, Browse templates, then Keycloak (Postgres). New to Levelrail? Install it on a fresh VPS first.

docker pull ghcr.io/glincker/levelrail:latest

Then levelrail-cli login --device. See Getting started and the Keycloak (Postgres) docs page.

Deploy Keycloak (Postgres) your way

Every format below deploys the same pinned images. Pick the one that fits how you work.

Deploy Keycloak (Postgres) from the CLI

levelrail-cli templates deploy keycloak-postgres --name my-keycloak-postgres

Deploy Keycloak (Postgres) with the API

Create a token in the dashboard first. This one-click route deploys it as a trial app you can keep or remove.

curl -X POST -H "Authorization: Bearer $TOKEN" \
  https://levelrail.example.com/api/v1/service-templates/keycloak-postgres/deploy

Keycloak (Postgres) configuration

Keycloak (Postgres) services

ServiceImagePortsVolumes
db postgres:16-alpine none keycloak_postgres_db_data -> /var/lib/postgresql/data
keycloak quay.io/keycloak/keycloak:26.1 8080 keycloak_postgres_data -> /opt/keycloak/data

Keycloak (Postgres) environment variables

VariableServiceValue
POSTGRES_DB db Preset by the template
POSTGRES_PASSWORD db Generated at deploy
POSTGRES_USER db Preset by the template
KC_BOOTSTRAP_ADMIN_PASSWORD keycloak Generated at deploy
KC_BOOTSTRAP_ADMIN_USERNAME keycloak Generated at deploy
KC_DB keycloak Preset by the template
KC_DB_PASSWORD keycloak Generated at deploy
KC_DB_URL keycloak Preset by the template
Show all 14 variables
  • KC_DB_USERNAMEkeycloakPreset by the template
  • KC_HEALTH_ENABLEDkeycloakPreset by the template
  • KC_HOSTNAMEkeycloakPreset by the template
  • KC_HTTP_ENABLEDkeycloakPreset by the template
  • KC_LEGACY_OBSERVABILITY_INTERFACEkeycloakPreset by the template
  • KC_PROXY_HEADERSkeycloakPreset by the template

Ports and volumes

Ports
8080
Volumes
2 named mounts: keycloak_postgres_db_data -> /var/lib/postgresql/data, keycloak_postgres_data -> /opt/keycloak/data

Keycloak (Postgres) FAQ

How much memory does Keycloak (Postgres) need?

The catalog lists about 1 GiB of memory for Keycloak (Postgres) across its 2 services.

Does Keycloak (Postgres) run on arm64?

For Keycloak (Postgres), an arm64 image is published; amd64 is image published.

What licence is Keycloak (Postgres) under?

Keycloak (Postgres) is licensed under Apache-2.0, which is permissive, with few conditions on reuse.

Does Keycloak (Postgres) need configuration before it starts?

No. The template fills in its own defaults and generates secrets at deploy time.

Which database does Keycloak (Postgres) bundle?

The template includes Postgres, running as its own service.

Which ports does Keycloak (Postgres) use?

Keycloak (Postgres) listens on port 8080 inside the stack.

Where does Keycloak (Postgres) keep its data?

In named volumes: keycloak_postgres_db_data mounted at /var/lib/postgresql/data and keycloak_postgres_data mounted at /opt/keycloak/data.

Can I deploy Keycloak (Postgres) on Dokploy or Dokku?

The services and pinned images on this page can be run on any Docker host. The public Dokploy templates list we compared does not have an entry with the same id for Keycloak (Postgres), so on Dokploy you would use a Docker Compose application with the file from this page. Dokku deploys container images with its own commands, so the pinned image postgres:16-alpine, quay.io/keycloak/keycloak:26.1 is what you deploy there.

levelrail-cli templates deploy keycloak-postgres --name my-keycloak-postgres