Just use pre-built image to start with:
FROM quay.io/keycloak/keycloak:latest
Use a Bash script to download Keycloak, and configure OS. Assumes you create a host.env config file and a /run/keycloak.env file:
wget https://raw.githubusercontent.com/JeffersonLab/smoothness/main/bash/keycloak/rhel9-setup.sh
chmod +x rhel9-setup.sh
./rhel9-setup.sh host.env
Copy/Edit keycloak.conf file into/at Keycloak conf dir then execute:
./kc.sh build
Note: To configure TLS copy PEM format TLS .crt and .key into the Keycloak conf dir and ensure keycloak.conf references the files.
export KEYCLOAK_ADMIN=username
export KEYCLOAK_ADMIN_PASSWORD=password
./kc.sh start --optimized
... wait for successful boot
Ctrl-C
unset KEYCLOAK_ADMIN
unset KEYCLOAK_ADMIN_PASSWORD
Keycloak supports export/import of JSON realm files. However, scripted kcadm.sh commands are clearer to understand and maintain.