How can i reimport a realm in keycloak. If it already exists

Viewed 726

Not able to import realm json using Keycloak import on keycloak version 15.0.2. I am running keycloak in a docker container.

Below is the docker volume in compose

volumes:

- ./keycloak-realm.json:/tmp/keycloak-realm.json

Environment variables for keycloak

KEYCLOAK_IMPORT=/tmp/keycloak-realm.json -Dkeycloak.profile.feature.upload_scripts=enabled -Dkeycloak.migration.strategy=OVERWRITE_EXISTING

The import fails with already exists error. When using migration strategy also getting the same error.

How can i import realm even if it exists?

Error from Keycloak:

04:47:48,047 INFO [org.keycloak.services] (ServerService Thread Pool -- 70) KC-SERVICES0003: Not importing realm sso from file /tmp/keycloak-realm.json. It already exists. 04:47:48,068 INFO [org.keycloak.services] (ServerService Thread Pool -- 70) KC-SERVICES0003: Not importing realm sso from file /tmp/keycloak-realm.json. It already exists.

1 Answers

If you are using the official docker image, you will need to set the strategy via JAVA_OPTS_APPEND environment variable. In your case:

KEYCLOAK_IMPORT=/tmp/keycloak-realm.json
JAVA_OPTS_APPEND=-Dkeycloak.profile.feature.upload_scripts=enabled -Dkeycloak.migration.strategy=OVERWRITE_EXISTING
Related