Data missing when importing realm

@lrxw

After some more trial and error the following is working for me:

docker container run -d --name keycloak \
  -p 10001:8080 \
  -v $(pwd):/tmp \
  -e KEYCLOAK_USER=admin \
  -e KEYCLOAK_PASSWORD=secret \
  jboss/keycloak:9.0.3

Export:

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

When the export is complete use Ctrl-C to exit the session.

Import the exported file into my Keycloak container.

Dockerfile:

FROM jboss/keycloak:9.0.3

ENV THEME_VERSION 1.0

USER root

RUN microdnf install -y unzip

COPY json /tmp

COPY ./serendipity-keycloak-theme-$THEME_VERSION.zip /opt/jboss/keycloak/themes
RUN cd /opt/jboss/keycloak/themes && \
    unzip serendipity-keycloak-theme-$THEME_VERSION.zip && \
    rm serendipity-keycloak-theme-$THEME_VERSION.zip

docker-compose.yml:

version: '3.7'

services:

  openldap:
    container_name: openldap
    build:
      context: ./services/openldap
      dockerfile: Dockerfile
    env_file: ./services/openldap/openldap.env
    ports:
      - "389:389"

  keycloak:
    container_name: keycloak
    build:
      context: ./services/keycloak
      dockerfile: Dockerfile
    ports:
      - "10001:8080"
    volumes:
      - .:/export
    env_file: ./services/keycloak/keycloak.env

  serendipity-api:
    container_name: serendipity-api
    build:
      context: .
      dockerfile: Dockerfile
    ports:
      - "3001:3001"
    volumes:
      - ./h2:/h2
    environment:
      SPRING_DATASOURCE_URL: jdbc:h2:/h2/serendipity
      AUTO_SERVER: 1
      AUTO_SERVER_PORT: 9091
      DB_CLOSE_DELAY: -1

keycloak.env:

KEYCLOAK_USER=admin
KEYCLOAK_PASSWORD=secret
KEYCLOAK_DEFAULT_THEME=serendipity
KEYCLOAK_IMPORT=/tmp/development-realm.json
KEYCLOAK_MIGRATION_STRATEGY=OVERWRITE_EXISTING
1 Like