Run Keycloak with Docker
The fastest way to run Keycloak locally is with Docker. The official image on quay.io includes everything you need — no separate database, no install steps. One command and Keycloak is listening on port 8080.
The start-dev command explained
Section titled “The start-dev command explained”Here is what each part of the docker run command does:
docker run --name keycloak— names the container so you can reference it later withdocker stop keycloakordocker rm keycloak.-p 8080:8080— maps port 8080 on the host to port 8080 inside the container, sohttp://localhost:8080reaches Keycloak.-e KC_BOOTSTRAP_ADMIN_USERNAME=admin— sets the initial admin username. This environment variable is only used on the very first boot when no admin account exists yet.-e KC_BOOTSTRAP_ADMIN_PASSWORD=admin— sets the initial admin password. Change this in any real environment — never leave it asadminoutside of local dev.quay.io/keycloak/keycloak:latest— the official Keycloak image from the Red Hat Quay registry. Pin to a specific version (e.g.26.7) in CI or staging.start-dev— starts Keycloak in development mode with an embedded H2 in-memory database and HTTP enabled. No TLS certificate is required.
docker run --name keycloak -p 8080:8080 \
-e KC_BOOTSTRAP_ADMIN_USERNAME=admin \
-e KC_BOOTSTRAP_ADMIN_PASSWORD=admin \
quay.io/keycloak/keycloak:latest start-devOpening the admin console
Section titled “Opening the admin console”- Wait for the log line that says
Keycloak X.Y.Z on JVM (powered by Quarkus) started— this means Keycloak is ready. - Open
http://localhost:8080in your browser. - Click “Administration Console”.
- Sign in with username
adminand passwordadmin. - You are now in the master realm’s admin console.
Admin console vs account console
Section titled “Admin console vs account console”The admin console (http://localhost:8080) is the management UI for administrators. You create realms, clients, users, roles, and identity providers here. Only team members who need to configure Keycloak should have access to it.
The account console (http://localhost:8080/realms/master/account) is the self-service portal for end users. Users can update their profile, change their password, and manage their active sessions here. Your application users land here, not the admin console. Each realm has its own account console at /realms/{realm-name}/account.
Stopping and removing the container
Section titled “Stopping and removing the container”# Stop the containerdocker stop keycloak# Remove the container (data is lost — this is dev mode)docker rm keycloakBecause start-dev uses an in-memory H2 database, all realms, clients, and users you created are gone when the container is removed. In the next module you will learn how to persist data with an external database.
Trade-offs
Section titled “Trade-offs”| Option | Benefit | Cost |
|---|---|---|
start-dev in a Docker container | Up and running with one command, no database setup needed — good for experimenting and learning | Data is lost every time the container is removed, there’s no TLS, and it’s not fit for a real workload, even staging |
start with an external database (production mode) | Data persists across restarts/redeploys, supports TLS and a fixed hostname, and scales across multiple instances | Requires setting up a database, TLS certificate, and reverse proxy before it can be used |
Common mistakes
Section titled “Common mistakes”- Running
start-devand forgetting to switch tostartbefore going to production —start-devdisables several security checks and uses an in-memory database; forgetting to switch modes means production data disappears the moment the container restarts. - Not changing
KC_BOOTSTRAP_ADMIN_USERNAME/KC_BOOTSTRAP_ADMIN_PASSWORDfrom the default — leavingadmin/adminin place, even in a container exposed to another network, is a very common security gap. - Not pinning the image version — using
quay.io/keycloak/keycloak:latestin CI or staging causes behaviour to change unexpectedly whenever a new version is released. Always pin to a specific version.
Real-world example
Platform engineering teams inside an organisation — commonly use
docker run start-devordocker-composeonly on a developer’s local machine for integration testing, then deploy the real Keycloak through a Helm chart on Kubernetes with an external PostgreSQL database.Red Hat build of Keycloak (RH-SSO) — the image used in this lesson is the community build; organisations that need an SLA-backed support contract use the Red Hat build of Keycloak container image instead, but the
start/start-devcommands and environment variables work the same way.