Keycloak
What is Keycloak?
Keycloak is an open-source identity and access management server: single sign-on, OAuth2/OpenID Connect, SAML, user federation, and admin consoles for managing realms and clients. Laradock runs it via the official Bitnami Keycloak image, backed by the postgres container.
Start Keycloak
Keycloak depends on postgres, so make sure it's running too:
docker compose up -d postgres keycloak
Stop Keycloak
docker compose stop keycloak
Configuration
Settings live in keycloak/defaults.env and can be overridden in your own .env:
| Variable | Default | What it does |
|---|---|---|
KEYCLOAK_VERSION | latest | Image tag from the Bitnami Keycloak Docker Hub page. |
KEYCLOAK_HTTP_PORT | 8081 | Host and container port Keycloak is published on. |
KEYCLOAK_CREATE_ADMIN_USER | true | Whether to auto-create the initial admin user on first boot. |
KEYCLOAK_ADMIN_USER | admin | Initial admin username. |
KEYCLOAK_ADMIN_PASSWORD | secret | Initial admin password. |
KEYCLOAK_POSTGRES_HOST | postgres | Hostname of the Postgres container Keycloak connects to. |
The database name, user, and password (KEYCLOAK_POSTGRES_DB, KEYCLOAK_POSTGRES_USER, KEYCLOAK_POSTGRES_PASSWORD) aren't in keycloak/defaults.env, they live in the root .env.example (default laradock_keycloak for all three) and are passed into the postgres container, which auto-creates that database and role on first boot when KEYCLOAK_POSTGRES_INIT=true (set in postgres/defaults.env).
Log in to the admin console
docker compose up -d postgres keycloak
Open http://localhost:8081 and sign in with admin / secret (or your own KEYCLOAK_ADMIN_USER/KEYCLOAK_ADMIN_PASSWORD).
Common issues
- Keycloak can't reach its database. Confirm
postgresis running (docker compose ps postgres) and thatKEYCLOAK_POSTGRES_INIT=truewas set the first timepostgresinitialized its data folder, that flag only creates the database/role on the very first boot. - Admin login fails after changing credentials.
KEYCLOAK_ADMIN_USER/KEYCLOAK_ADMIN_PASSWORDonly seed the admin account on first boot. Changing them later in.envdoesn't update the existing user, change the password from inside the admin console instead. - Port already in use. Change
KEYCLOAK_HTTP_PORTin.envand restart:docker compose up -d keycloak.
Need a general-purpose Postgres database instead? See the Databases guide. New to Laradock? Start at Getting Started.