How to run Keycloak with MySQL Database as Docker Containers

I. Introduction

In this blog, we will create a docker-compose file that will run a Keycloak and MySQL instance as a docker container. Keycloak will connect to the MySQL database using JDBC.

II. Prerequisites

Docker must be running on your local machine.

III. What should be inside the project?

IV. The Docker Compose File

version: "3"networks: 
backend:
frontend:
services:
keycloak:
image: jboss/keycloak:10.0.2
environment:
KEYCLOAK_USER: admin
KEYCLOAK_PASSWORD: kerri
DB_ADDR: mysql
DB_USER: keycloak
DB_PASSWORD: keycloak
DB_PORT: "3306"
DB_DATABASE: keycloak
KEYCLOAK_IMPORT: /tmp/import-realm.json
ports:
- 8080:8080
volumes:
- ./keycloak:/tmp
networks:
- backend
- frontend
mysql:
image: mysql:8.0.20
environment:
MYSQL_ROOT_PASSWORD: kerri
MYSQL_USER: keycloak
MYSQL_PASSWORD: keycloak
MYSQL_DATABASE: keycloak
ports:
- 3306:3306
networks:
- backend
adminer:
image: adminer
restart: always
ports:
- 8081:8080
networks:
- backend
- frontend

Download the project at .

Originally published at .

Senior Java Developer with 15 years of professional experience | Startup enthusiast.