no

How to Containerized Keycloak With Mysql in Docker

Introduction In this blog, we will create a docker-compose file that will run a Keycloak and MySQL instance as a docker container. Keycloak ...

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.

Prerequisites

Docker must be running on your local machine.

What should be inside the project?

  • The docker compose file
  • keycloak/import-realm.json - This realm will imported into Keycloak once a new instance is created. This file is use in the exercise available at https://github.com/czetsuya/keycloak-angular-auth/blob/master/config/keycloak-auth-realm.json.

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/czetsuyatech/docker-keycloak-mysql.

Development and Support

Unlock the full coding experience! As a GitHub Sponsor, you gain exclusive access to the code behind this article—start learning and building today!

I'm available for contracting services and support. You can reach me at: https://www.czetsuyatech.com/p/consultation-services.html.

Related

docker 5249056117875196902

Post a Comment Default Comments

item