# ![Keycloak](<https://daemonless.io/images/logos/keycloak.svg>) Keycloak

[![Build Status](<https://img.shields.io/github/actions/workflow/status/daemonless/keycloak/build.yaml?style=flat-square&label=Build&color=green>)](<https://github.com/daemonless/keycloak/actions>) [![Last Commit](<https://img.shields.io/github/last-commit/daemonless/keycloak?style=flat-square&label=Last+Commit&color=blue>)](<https://github.com/daemonless/keycloak/commits>) [![OCI Pulls](<https://img.shields.io/docker/pulls/daemonless/keycloak?style=flat-square&label=OCI+Pulls&color=blue>)](<https://hub.docker.com/r/daemonless/keycloak>)

Open source identity and access management with single sign-on, OpenID Connect, OAuth 2.0 and SAML.

|  |  |
| --- | --- |
| **Port** | `8080` |
| **Registry** | [`ghcr.io/daemonless/keycloak`](<https://github.com/daemonless/keycloak/pkgs/container/keycloak>) |
| **Daemonless** | [daemonless/keycloak](<https://github.com/daemonless/keycloak>) |
| **Source** | [keycloak/keycloak](<https://github.com/keycloak/keycloak>) |
| **Website** | [www.keycloak.org](<https://www.keycloak.org/>) |

## Commands

As in the official image, the container command goes to `kc.sh`. Without one it runs `start` (production mode). Use `command: ["kc.sh", "start-dev"]` to try Keycloak in development mode.

## Reverse proxy and TLS

The example serves HTTP on 8080 behind a TLS-terminating reverse proxy. For TLS in Keycloak itself, drop `KC_HTTP_ENABLED`, set `KC_HTTPS_CERTIFICATE_FILE` and `KC_HTTPS_CERTIFICATE_KEY_FILE`, and publish 8443.

## Database

Without `KC_DB`, Keycloak uses an H2 file database on `/data`, which is not supported in production. Set `KC_DB`, `KC_DB_URL`, `KC_DB_USERNAME` and `KC_DB_PASSWORD` for PostgreSQL or MariaDB.

## Memory

All variants run OpenJDK 25. The JVM can't see jail memory limits on FreeBSD, so the default heap is 70% of the host's RAM. Set `JAVA_OPTS_KC_HEAP` (e.g. `-Xms512m -Xmx1g`) on shared hosts.

## Prerequisites

Before deploying, ensure your host environment is ready. See the [Quick Start Guide](<https://daemonless.io/guides/quick-start/index.md>) for host setup instructions, including the security model for host vs. container privileges.

## Deployment

**Customize Paths, UID & Ports**

Install and manage **Keycloak** on FreeBSD with [fjord](<https://fjord.daemonless.io>):

```
fjord install keycloak
```

Or open the **App Store** in the fjord web UI and install **Keycloak** from the wizard. New to fjord? See the [Install Guide](<https://fjord.daemonless.io/install/>).

```
services:
  keycloak:
    image: "ghcr.io/daemonless/keycloak:latest"
    container_name: keycloak
    environment:
      - PUID=1000  # User ID for the application process
      - PGID=1000  # Group ID for the application process
      - TZ=UTC  # Timezone for the container
      - KC_HOSTNAME=  # Public URL of Keycloak, e.g. https://auth.example.org. Required in production mode.
      - KC_BOOTSTRAP_ADMIN_USERNAME=admin  # Temporary admin user, created on the first start only
      - KC_BOOTSTRAP_ADMIN_PASSWORD=<KC_BOOTSTRAP_ADMIN_PASSWORD>  # Password of the temporary admin user
      - KC_HTTP_ENABLED=true  # Serve plain HTTP on 8080, for TLS at a reverse proxy
      - KC_PROXY_HEADERS=xforwarded  # Trust the reverse proxy's forwarded headers: xforwarded or forwarded
      - KC_HEALTH_ENABLED=true  # Health endpoints on management port 9000, used by the healthcheck
      # - KC_DB=  # Database vendor: postgres, mariadb, mysql, mssql or oracle. Default: dev-file (H2 on /data, not for production)
      # - KC_DB_URL=  # JDBC URL of the database, e.g. jdbc:postgresql://db/keycloak
      # - KC_DB_USERNAME=  # Database user
      # - KC_DB_PASSWORD=  # Database password
      # - JAVA_OPTS_KC_HEAP=  # JVM heap options, e.g. -Xms512m -Xmx1g. Default: 70% of the host's RAM
    volumes:
      - "/containers/keycloak:/config"
      - "/containers/keycloak/data:/data"
    ports:
      - "8080:8080"
    # always (not unless-stopped) so FreeBSD's podman rc.d auto-starts it at boot
    restart: always
```

Save as `compose.yaml`, then run `podman-compose up -d`.

> [!WARNING]
>
> Exposing ports in AppJail means that your service can be reached from remote hosts. If that is not your intention, do not expose the ports and communicate with the service using the jail's IPv4 address or hostname assigned by the virtual network.

```
# .env

DIRECTOR_PROJECT=keycloak
PUID=1000
PGID=1000
TZ=UTC
KC_HOSTNAME=
KC_BOOTSTRAP_ADMIN_USERNAME=admin
KC_BOOTSTRAP_ADMIN_PASSWORD=<KC_BOOTSTRAP_ADMIN_PASSWORD>
KC_HTTP_ENABLED=true
KC_PROXY_HEADERS=xforwarded
KC_HEALTH_ENABLED=true
```

```
# appjail-director.yml

options:
  - virtualnet: ':<random> default'
  - nat:
services:
  keycloak:
    name: keycloak
    options:
      - container: 'args:--pull'
      - expose: '8080:8080 proto:tcp'
    oci:
      user: root
      environment:
        - PUID: !ENV '${PUID}'
        - PGID: !ENV '${PGID}'
        - TZ: !ENV '${TZ}'
        - KC_HOSTNAME: !ENV '${KC_HOSTNAME}'
        - KC_BOOTSTRAP_ADMIN_USERNAME: !ENV '${KC_BOOTSTRAP_ADMIN_USERNAME}'
        - KC_BOOTSTRAP_ADMIN_PASSWORD: !ENV '${KC_BOOTSTRAP_ADMIN_PASSWORD}'
        - KC_HTTP_ENABLED: !ENV '${KC_HTTP_ENABLED}'
        - KC_PROXY_HEADERS: !ENV '${KC_PROXY_HEADERS}'
        - KC_HEALTH_ENABLED: !ENV '${KC_HEALTH_ENABLED}'
    volumes:
      - keycloak: /config
      - keycloak_data: /data
volumes:
  keycloak:
    device: '/containers/keycloak'
  keycloak_data:
    device: '/containers/keycloak/data'
```

```
# Makejail

ARG tag=latest

OPTION container=boot
OPTION overwrite=force
OPTION from=ghcr.io/daemonless/keycloak:${tag}
```

Save the files above, then run `appjail-director up`.

> [!WARNING]
>
> **Experimental**
>
> Bastille's OCI support is experimental. It requires `buildah` and shares the host network stack (`inherit`). Mount volumes with `--volume HOST JAIL`; without it, image-declared volumes are stored under `${bastille_volumesdir}/${jail}`.

```
services:
  keycloak:
    name: keycloak
    image: "ghcr.io/daemonless/keycloak:latest"
    network:
      - mode: host
    environment:
      - PUID=1000
      - PGID=1000
      - TZ=UTC
      - KC_HOSTNAME=
      - KC_BOOTSTRAP_ADMIN_USERNAME=admin
      - KC_BOOTSTRAP_ADMIN_PASSWORD=<KC_BOOTSTRAP_ADMIN_PASSWORD>
      - KC_HTTP_ENABLED=true
      - KC_PROXY_HEADERS=xforwarded
      - KC_HEALTH_ENABLED=true
    volumes:
      - "/containers/keycloak:/config"
      - "/containers/keycloak/data:/data"
```

Save as `bastille-compose.yml`, then run `bastille up`.

## Parameters

### Environment Variables

| Variable | Default | Description |
| --- | --- | --- |
| `PUID` | `1000` | User ID for the application process |
| `PGID` | `1000` | Group ID for the application process |
| `TZ` | `UTC` | Timezone for the container |
| `KC_HOSTNAME` | \`\` | Public URL of Keycloak, e.g. [https://auth.example.org](<https://auth.example.org>). Required in production mode. |
| `KC_BOOTSTRAP_ADMIN_USERNAME` | `admin` | Temporary admin user, created on the first start only |
| `KC_BOOTSTRAP_ADMIN_PASSWORD` | `<KC_BOOTSTRAP_ADMIN_PASSWORD>` | Password of the temporary admin user |
| `KC_HTTP_ENABLED` | `true` | Serve plain HTTP on 8080, for TLS at a reverse proxy |
| `KC_PROXY_HEADERS` | `xforwarded` | Trust the reverse proxy's forwarded headers: xforwarded or forwarded |
| `KC_HEALTH_ENABLED` | `true` | Health endpoints on management port 9000, used by the healthcheck |
| `KC_DB` | \`\` | Database vendor: postgres, mariadb, mysql, mssql or oracle. Default: dev-file (H2 on /data, not for production) |
| `KC_DB_URL` | \`\` | JDBC URL of the database, e.g. jdbc:postgresql://db/keycloak |
| `KC_DB_USERNAME` | \`\` | Database user |
| `KC_DB_PASSWORD` | `<KC_DB_PASSWORD>` | Database password |
| `JAVA_OPTS_KC_HEAP` | \`\` | JVM heap options, e.g. -Xms512m -Xmx1g. Default: 70% of the host's RAM |

### Volumes

| Path | Description |
| --- | --- |
| `/config` | Home directory; set KC\_CONFIG\_FILE=/config/keycloak.conf to use a config file |
| `/data` | Keycloak data directory: H2 database (without KC\_DB) and import/ for --import-realm |

### Ports

| Port | Protocol | Description |
| --- | --- | --- |
| `8080` | TCP | HTTP (KC\_HTTP\_ENABLED=true) |

## Version Tags

Multi-arch manifests — resolve automatically to the right image for your platform.

| Tag | Description | Best For |
| :--- | :--- | :--- |
| `latest` | Official upstream Keycloak distribution on OpenJDK 25 (tracks latest release). | Most users — recommended. |
| `pkg` / `pkg-quarterly` | **FreeBSD Quarterly**. Uses stable, tested packages. | Production stability. |
| `pkg-latest` | **FreeBSD Latest**. Rolling package updates. | Staying current. |

| Tag | Description | Best For |
| :--- | :--- | :--- |
| `latest-amd64` | Official upstream Keycloak distribution on OpenJDK 25 (tracks latest release). | Most users — recommended. |
| `pkg-amd64` / `pkg-quarterly-amd64` | **FreeBSD Quarterly**. Uses stable, tested packages. | Production stability. |
| `pkg-latest-amd64` | **FreeBSD Latest**. Rolling package updates. | Staying current. |

| Tag | Description | Best For |
| :--- | :--- | :--- |
| `latest-aarch64` | Official upstream Keycloak distribution on OpenJDK 25 (tracks latest release). | Most users — recommended. |
| `pkg-aarch64` / `pkg-quarterly-aarch64` | **FreeBSD Quarterly**. Uses stable, tested packages. | Production stability. |
| `pkg-latest-aarch64` | **FreeBSD Latest**. Rolling package updates. | Staying current. |

> [!NOTE]
>
> **Implementation Details**
>
> - **Architectures:** amd64, aarch64
> - **User:** `bsd` (UID/GID set via [PUID/PGID](<https://daemonless.io/guides/permissions/index.md>)). Defaults to `1000:1000`.
> - **Base:** Built on `ghcr.io/daemonless/base` (FreeBSD 15.1).

---

Need help? Join our [Discord](<https://discord.gg/Kb9tkhecZT>) community.
