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 https://github.com/czetsuya/docker-keycloak-mysql.

Originally published at https://www.czetsuyatech.com/2020/06/how-to-run-keycloak-with-mysql-database-on-docker.html.

--

--

--

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

Love podcasts or audiobooks? Learn on the go with our new app.

Deploy an ASP.NET Core App with EF Core and PostgreSQL to Google Cloud

Isolates Programming in Flutter

Who? Why? What? Fix? - System.gc()

If You’re Angry About Kyle Rittenhouse Deputizing Himself to Police Kenosha, WI, Because You Think…

FastSpark: A New Fast Native Implementation of Spark from Scratch

Configure Webserver & Haproxy and add IP’s dynamically in haproxy.cfg

So many permissions, so little time!

Python — 5

Get the Medium app

A button that says 'Download on the App Store', and if clicked it will lead you to the iOS App store
A button that says 'Get it on, Google Play', and if clicked it will lead you to the Google Play store
czetsuya

czetsuya

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

More from Medium

Deploying Keycloak with SSL in just 10 minutes!

How to set up Keycloak with Docker and PostgreSQL

Access Oracle Database XE via Docker

Docker NGINX as Reverse Proxy