Export and Import of Realm from Keycloak

Ramanamuttana
3 min readAug 30, 2023

--

Import:

In essence, the exported realm is missing a confidential/secret code.

Secret code in * which means the code is missing

While we can generate a new secret code after the docker container running , the docker containers that operate along with Keycloak need this confidential/secret code before starting, posing an issue. The resolution options are:
a) Manually modify realm-export.json by taking the secret code from the previous Keycloak docker container i.e before stopping the container and inserting it into the exported realm-export.json file.
b) Preemptively introduce the upstream URL to realm.json and subsequently to Keycloak.

Now it is the time to add realm-export.json to keycloak docker container

i) Manually

ii) Through the docker compose

a) Manually

click on the create realm →click on Browse →add realm-export. json ( exported realm) → after import done click on the Create button .

selecting the realm
after adding ream-export.json

Note : incase if you face any issue like script is disabled and can not upload a realm-export.json , just follow the below tutorials .

now you can see the realm that you imported for example in my case Test Realm as shown below

test realm

b) Through docker compose file

 keycloak:
image: quay.io/keycloak/keycloak:21.1.1
command:
- "start-dev"
- "--http-port=8070"
environment:
- "KEYCLOAK_IMPORT= /opt/jboss/keycloak/imports/realm-export.json"
- "KEYCLOAK_ADMIN=admin"
- "KEYCLOAK_ADMIN_PASSWORD=admin"
volumes:
- ./imports/realm-export.json:/opt/jboss/keycloak/imports/realm-export.json
ports:
- 8070:8070

Export :

export on the right side corner

Now click on the partial export and select on for both options and click on Export

export with clients and groups

now we will get a json file , which you can use for import during the next keycloak container run.

--

--