Get started with Keycloak on Docker

Before you start

Make sure you have Docker installed.

Start Keycloak

From a terminal start Keycloak with the following command:

docker run -p 8080:8080 -e KEYCLOAK_ADMIN=admin -e KEYCLOAK_ADMIN_PASSWORD=admin start-dev

This will start Keycloak exposed on the local port 8080. It will also create an initial admin user with username admin and password admin.

Login to the admin console

Go to the Keycloak Admin Console and login with the username and password you created earlier.

Create a realm

A realm in Keycloak is the equivalent of a tenant. It allows creating isolated groups of applications and users. By default there is a single realm in Keycloak called master. This is dedicated to manage Keycloak and should not be used for your own applications.

Let’s create our first realm.

  1. Open the Keycloak Admin Console

  2. Hover the mouse over the dropdown in the top-left corner where it says master, then click on Create realm

  3. Fill in the form with the following values:

    • Realm name: myrealm

  4. Click Create

Add Realm

Create a user

Initially there are no users in a new realm, so let’s create one:

  1. Open the Keycloak Admin Console

  2. Click Users (left-hand menu)

    • Click Create new user (top-right corner of table)

  3. Fill in the form with the following values:

    • Username: myuser

    • First Name: Your first name

    • Last Name: Your last name

  4. Click Create

Add User

The user will need an initial password set to be able to login. To do this:

  1. Click Credentials (top of the page)

  2. Fill in the Set password form with a password

  3. Click ON next to Temporary to prevent having to update password on first login

Set Password

Login to account console

Let’s now try to login to the account console to verify the user is configured correctly.

  1. Open the Keycloak Account Console

  2. Login with myuser and the password you created earlier

You should now be logged-in to the account console where users can manage their accounts.

Keycloak Account Console

Secure your first app

Let’s try to secure our first application. First step is to register this application with your Keycloak instance:

  1. Open the Keycloak Admin Console

  2. Click 'Clients'

  3. Click 'Create client'

  4. Fill in the form with the following values:

    • Client type: OpenID Connect

    • Client ID: myclient

  5. Click 'Next'

  6. Make sure 'Standard flow' is enabled

  7. Click 'Save'

Add Client

After the client is created you need to update the following values for the client:

  1. Valid redirect URIs:*

  2. Web origins:

Remember to click Save.

Update Client

To make it easy for you we have a SPA testing application available on the Keycloak website.

Open and click Save to use the default configuration.

Now you can click Sign in to authenticate to this application using the Keycloak server you started earlier.


Before you go and run Keycloak in production there are a few more things that you will want to do, including:

  • Switch to a production ready database such as PostgreSQL

  • Configure SSL with your own certificates

  • Switch the admin password to a more secure password

For more information check out the server guides.

On this page