Keycloak serves as the central authentication and token management server for the TDEI project. It provides secure and efficient identity management, handling all aspects of user registration, authentication, and token management.
Create a file named .env in your project directory and add the required environment variables:
| Environment Variable | Value | Description |
|---|---|---|
KC_DB_URL |
jdbc:postgresql://your-db-host:5432/your-db-name |
Database connection URL |
KC_DB_USERNAME |
your-db-username |
Database username |
KC_DB_PASSWORD |
your-db-password |
Database password |
KC_DB_SCHEMA |
keycloak |
Database schema for Keycloak |
KC_HEALTH_ENABLED |
true |
Enables health check endpoints |
KC_HTTP_MANAGEMENT_HEALTH_ENABLED |
false |
Expose /health on the main HTTP port (8080) instead of management port 9000 |
KC_HOSTNAME_STRICT |
false |
Disables strict hostname checks |
KC_HOSTNAME |
https://your-keycloak-host |
Optional public hostname (recommended in production) |
KC_HTTP_ENABLED |
true |
Enables HTTP support (required behind TLS-terminating proxy) |
KC_PROXY_HEADERS |
forwarded or xforwarded |
Proxy headers to trust; must match what the reverse proxy sends |
KC_BOOTSTRAP_ADMIN_USERNAME |
admin |
Initial Keycloak admin username (first start only) |
KC_BOOTSTRAP_ADMIN_PASSWORD |
admin-password |
Initial Keycloak admin password (first start only) |
Use the --env-file option when running the container:
Build the Docker Image
docker build -t keycloak-custom .
Run the Docker Container with the .env File
docker run --env-file .env -p 8080:8080 keycloak-custom
Instead of using a .env file, you can pass variables directly in the command:
docker run -e KC_DB_URL="jdbc:postgresql://your-db-host:5432/your-db-name"
-e KC_DB_USERNAME="your-db-username"
-e KC_DB_PASSWORD="your-db-password"
-e KC_BOOTSTRAP_ADMIN_USERNAME="admin"
-e KC_BOOTSTRAP_ADMIN_PASSWORD="admin-password"
-e KC_HTTP_ENABLED="true"
-e KC_PROXY_HEADERS="forwarded"
-p 8080:8080 keycloak-custom
Once the container is running, access the Keycloak Admin Console at:
- URL: http://localhost:8080/admin
- Default Admin Credentials:
- Username: admin
- Password: admin (Update credentials for security!)
- user admin@tdei.com creds is reset for security and it is created with default password in config.
- credential secrets are regenerted for each TDEI clients
- Realm email SMTP password is set.
The TDEI custom theme is copied to Keycloak’s themes directory
The TDEI realm configuration is imported on startup from tdei-realm.json