Running Keycloak Container On Apple Silicon CPU (M1, M2)

Overview

Recently, due to the degradation of my internet connection, I was unable to use my remote keycloak instance hosted on Digital Ocean New York server. My only choice to be able to develop again is to create a local Keycloak instance.

The bad news is when I ran the container using jboss/keycloak image, I got some error relating to CPU architecture is not supported. I’m using Macbook Air M1, btw.

So I decided to build the image myself.

How to run Keycloak Container if you have M1/M2 mac

For now, you can easily create a new Keycloak instance using this image:

https://hub.docker.com/r/codingpuss/keycloak-silicon

For example, here is my docker-compose file:

version: '3'

services:
  keycloak:
    container_name: keycloak
    image: codingpuss/keycloak-silicon:16.1.1
    restart: always
    env_file: ./keycloak.env
    depends_on:
      - keycloak_db
    
    ports:
      - "18080:8080"
    networks:
      - keycloak-net


  keycloak_db:
    container_name: keycloak_db
    image: mariadb:10.6.0
    restart: always
    volumes:
      - keycloak_db_vol:/var/lib/mysql
    env_file:
      - ./keycloak-db.env
    networks:
      - keycloak-net

volumes:
  keycloak_db_vol:

networks:
  keycloak-net:

The keycloak.env file:

KEYCLOAK_USER=kc_dev
KEYCLOAK_PASSWORD=kc_dev1231232
KEYCLOAK_EXTRA_ARGS="-Dkeycloak.profile.feature.upload_scripts=enabled"
DB_VENDOR=mariadb
DB_ADDR=keycloak_db:3306
DB_DATABASE=keycloak_1
DB_USER=root
DB_PASSWORD=root

The keycloak-db.env file

MYSQL_ROOT_PASSWORD=root
MYSQL_DATABASE=keycloak_1

That’s it! You can run keycloak on Apple Silicon CPU now.

For the curious

If you want to build your own image using different keycloak versions, this is the GitHub repo

Leave a Comment