Export realm settings with Keycloak in Docker

when exporting realm through Docker the following error happens:

I get the following error message:

ERROR: Error during export/import: /opt/keycloak/data/import/your-realm.json (Permission denied)

To resolve this, run the command using the root proveleges

docker exec -u root -t -i <container_id> /bin/bash

then execute the command to export /opt/keycloak/bin/kc.sh export --dir /opt/keycloak/data/import --realm {your-realms-id} --users realm_file

With --dir or --file you can specify the export folder or file. --users realm_file will cause that the users will be put into the realm file. --realm {your-realms-id} is used to specify which realm is supposed to be exported.

Copy exported realm file to host

Using cat to view the contents of the realm file is nice, but here is the command to copy it over to your machine.

docker cp {your-containers-id}:/opt/keycloak/data/import/{your-realm-id}-realm.json /{your-desired-location-on-host}
0
Subscribe to my newsletter

Read articles from Abizeyimana Victor directly inside your inbox. Subscribe to the newsletter, and don't miss out.

Written by

Abizeyimana Victor
Abizeyimana Victor

I will raise your revenues or decrease your costs using solutions based on logic and in most cases, it will involve a computer. Design - Build - Improve. I design solutions to your business problem, build it with you and your team and finally scale the solution to fix other related problems. I use Javascript and Python as the main languages for development but I am eager and faster to learn anything that would be put a solution on the table.