Containerized solution for running Keycloak with PostgreSQL, monitoring via Prometheus and Grafana.
-
Prerequisites:
- Docker (v20.10.7+)
- Docker Compose (v2.0.0+)
-
Clone repository:
git clone https://github.com/eabykov/keycloak-compose.git cd keycloak-compose
-
Start the system:
docker compose up -d
-
Access services:
- Keycloak: http://localhost:8080
- Grafana: http://localhost:3000
- Prometheus: http://localhost:9090
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 | URL | Credentials |
---|---|---|
Keycloak | http://localhost:8080 | admin / keycloak |
Grafana | http://localhost:3000 | admin / grafana |
Prometheus | http://localhost:9090 | No authentication |
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
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 |
# Live container resource usage
docker stats
# Check service status
docker compose ps
After launch:
- Access Keycloak Admin Console
- Create new realm
- Configure clients and users
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!
If services fail to start:
- Check port conflicts (8080, 9090, 3000)
- Inspect logs:
docker compose logs keycloak
- Verify no conflicting containers:
docker ps -a