# Keycloak in production mode with PostgreSQL, for an exe.dev VM. # From https://exe.dev/deploy/keycloak. Secrets and the VM name come from .env. name: keycloak services: postgres: image: postgres:18 restart: unless-stopped environment: POSTGRES_DB: keycloak POSTGRES_USER: keycloak POSTGRES_PASSWORD: ${POSTGRES_PASSWORD} volumes: - ./postgres:/var/lib/postgresql healthcheck: test: ["CMD-SHELL", "pg_isready -U keycloak -d keycloak"] interval: 10s retries: 10 keycloak: image: quay.io/keycloak/keycloak:26.8.2 restart: unless-stopped command: start mem_limit: 2g environment: KC_DB: postgres KC_DB_URL_HOST: postgres KC_DB_URL_DATABASE: keycloak KC_DB_USERNAME: keycloak KC_DB_PASSWORD: ${POSTGRES_PASSWORD} # Public URL for logins and tokens; the admin console has its own. KC_HOSTNAME: https://${VM}.exe.xyz KC_HOSTNAME_ADMIN: https://${VM}.exe.xyz:8080 # exe.dev ends TLS; nginx passes plain HTTP with X-Forwarded-* headers. KC_HTTP_ENABLED: "true" KC_PROXY_HEADERS: xforwarded KC_HEALTH_ENABLED: "true" KC_CACHE: local # A temporary admin for the first start only; install replaces it. KC_BOOTSTRAP_ADMIN_USERNAME: temp-admin KC_BOOTSTRAP_ADMIN_PASSWORD: ${KC_BOOTSTRAP_ADMIN_PASSWORD} ports: - 127.0.0.1:8180:8080 - 127.0.0.1:9000:9000 healthcheck: test: ["CMD-SHELL", "exec 3<>/dev/tcp/127.0.0.1/9000 && printf 'GET /health/ready HTTP/1.0\\r\\n\\r\\n' >&3 && grep -q 'HTTP/1.. 200' <&3"] interval: 10s start_period: 120s retries: 10 depends_on: postgres: condition: service_healthy