Docker

docker-compose.yml For KeyCloak – Local Development

Last Updated on

This post shows how to craft a basic docker-compose.yml file to start up a Keycloak Docker container with a first user account in a local development environment.

A docker-compose.yml

The docker-compose.yml that we use for this post has the following content. It uses a Docker image from JBoss and has a configuration for an initial user within KeyCloak. Moreover, it uses a bridge network. If we want to add other Docker images, we need to include them in the same network by using networks.

There are two commented lines. See the last section of this post on changing ports.

Start-Up Container For KeyCloak

Open a Windows Command Line prompt. Then, change to the directory where the docker-compose.yml file for KeyCloak container. Then, run the following commands in order.

The following command will pull the KeyCloak image Docker Hub to the local machine. If we added other images in the docker-compose.yml file, the command would put them too.

Then, create and run a Keycloak container. The following command only targets the creation of a KeyCloak container.

If we want to create and run all containers for all the images we defined in the docker-compose.yml, we can use the following command.

Then, we can access the Keycloak Web console via http://localhost:8080.

Change Ports

In case we wish to change to entry port to something other than 8080, simply uncomment the commented lines. Then, comment out - 8080:8080. The -Djboss.socket.binding.port-offset=200  will change the port to Keycloak port to 8280  (from 8080 + 200).

For example, we want to use port 9999. We change the value for ports to 9999:9999 and with an offset of 1919. The modified docker-compose.yml would like the following.

Another example, we want to use port 8181. Change the value for ports to 8181:8181 and set the offset to 101.

The file docker-compose.yml is just for a local development environment.

This post is part of the Docker For Developers tutorial.

You Might Also Like