2026-02-10 12:38:07 +03:00
2026-02-10 12:38:07 +03:00
2025-11-07 11:37:58 +03:00
2025-07-25 11:01:36 +03:00

Keycloak with PostgreSQL, Prometheus & Grafana

Containerized solution for running Keycloak with PostgreSQL, monitoring via Prometheus and Grafana.

🚀 Quick Start

  1. Prerequisites:

  2. Clone repository:

    git clone https://github.com/eabykov/keycloak-compose.git
    cd keycloak-compose
    
  3. Start the system:

    docker compose up -d
    
  4. Access services:

⚙️ Configuration

Configure using the .env file. Key parameters:

Variable Default Description
POSTGRES_DB keycloak PostgreSQL database name
POSTGRES_USER keycloak PostgreSQL user
POSTGRES_PASSWORD password PostgreSQL password
KEYCLOAK_ADMIN admin Keycloak admin username
KEYCLOAK_ADMIN_PASSWORD keycloak Keycloak admin password
GRAFANA_ADMIN_PASSWORD grafana Grafana admin password

Modify .env before first launch.

🔌 Service Access

Service URL Credentials
Keycloak http://localhost:8080 admin / keycloak
Grafana http://localhost:3000 admin / grafana
Prometheus http://localhost:9090 No authentication

📊 Monitoring

Automatically configured:

  • Prometheus scrapes Keycloak metrics every 15s
  • Grafana with pre-configured Keycloak Dashboard
  • Ready-to-use dashboards for:
    • JVM metrics
    • Database queries
    • Active sessions
    • Authentication errors

🛠 Management

Core Commands

Command Description
docker compose up -d Start all services in background
docker compose down Stop services (add -v to remove volumes)
docker compose logs -f Follow service logs in real-time
docker compose restart keycloak Restart Keycloak container

Resource Monitoring

# Live container resource usage
docker stats

# Check service status
docker compose ps

Keycloak Administration

After launch:

  1. Access Keycloak Admin Console
  2. Create new realm
  3. Configure clients and users

🧹 Cleanup

Remove all containers, images, and volumes:

docker compose down -v --rmi all
docker system prune -a -f --volumes

Warning


These commands permanently destroy all data!

⁉️ Troubleshooting

If services fail to start:

  1. Check port conflicts (8080, 9090, 3000)
  2. Inspect logs:
    docker compose logs keycloak
    
  3. Verify no conflicting containers:
    docker ps -a
    

📚 Resources