Skip to content

Keycloak Docker

Keycloak Docker

Run container

docker run -p 8090:8090 -e KEYCLOAK_USER=admin -e KEYCLOAK_PASSWORD=admin -v $(pwd):/tmp --name keyc quay.io/keycloak/keycloak:12.0.3
-v $(pwd) stands for folder to save exported realm

Export realm

docker exec -it keyc /opt/jboss/keycloak/bin/standalone.sh \
-Djboss.socket.binding.port-offset=100 -Dkeycloak.migration.action=export \
-Dkeycloak.migration.provider=singleFile \
-Dkeycloak.migration.realmName=usersapp \
-Dkeycloak.migration.usersExportStrategy=REALM_FILE \
-Dkeycloak.migration.file=/tmp/my_realm.json

Start keycloak container with importing realm

docker-compose.yml

version: '3'

services:
  keycloak:
    image: quay.io/keycloak/keycloak:12.0.3
    volumes:
      - /tmp:/opt/jboss/keycloak/imports
    command: 
      -Djboss.socket.binding.port-offset=10
    environment:
      - KEYCLOAK_USER=admin
      - KEYCLOAK_PASSWORD=admin
      - KEYCLOAK_IMPORT=/opt/jboss/keycloak/imports/my_realm.json
      - DB_VENDOR=h2
    ports:
      - 8090:8090

Run

docker-compose up