services: keycloak-postgres: image: postgres:16 restart: unless-stopped environment: POSTGRES_DB: ${POSTGRES_DB} POSTGRES_USER: ${POSTGRES_USER} POSTGRES_PASSWORD: ${POSTGRES_PASSWORD} PGDATA: /var/lib/postgresql/data/pgdata expose: - "5432" networks: - internal volumes: - keycloak_postgres_data:/var/lib/postgresql/data healthcheck: test: ["CMD-SHELL", "pg_isready -U ${POSTGRES_USER} -d ${POSTGRES_DB}"] interval: 10s timeout: 5s retries: 10 start_period: 20s keycloak: build: context: ./keycloak dockerfile: Dockerfile restart: unless-stopped command: start environment: KC_DB: postgres KC_DB_URL: jdbc:postgresql://keycloak-postgres:5432/${POSTGRES_DB} KC_DB_USERNAME: ${POSTGRES_USER} KC_DB_PASSWORD: ${POSTGRES_PASSWORD} KC_BOOTSTRAP_ADMIN_USERNAME: ${KC_BOOTSTRAP_ADMIN_USERNAME} KC_BOOTSTRAP_ADMIN_PASSWORD: ${KC_BOOTSTRAP_ADMIN_PASSWORD} KC_HOSTNAME: https://${KC_PUBLIC_HOSTNAME} KC_HOSTNAME_STRICT: "true" KC_HTTP_ENABLED: "true" KC_PROXY_HEADERS: xforwarded KC_METRICS_ENABLED: "true" KC_HEALTH_ENABLED: "true" expose: - "8080" - "9000" networks: - proxy - internal depends_on: keycloak-postgres: condition: service_healthy volumes: keycloak_postgres_data: external: true name: keycloak_keycloak_postgres_data networks: proxy: external: true internal: driver: bridge