Export Realm, Users in Quarkus Keycloak
This post demonstrates how to export a keycloak realm and its users on quarkus keycloak 19. The exported realm and users can be used to seed the service during integration test.
Attention: snippets in this post are intended to be used for development ONLY.
The keycloak guide for import and export details how to do this.
All files needed for this demonstration can be found here
- Start the docker services:
clone the repository and start the both services: postgres and docker. If using Intellij, you can simply click the play icon next to the service. Otherwise run the following to startup all the services
2. Run the export command
Using the docker exec command, access the running keycloak container and execute the following command. If using docker desktop, you can also click the console icon to access the container
3. Volume Binding
Notice in the volumes definition of the keycloak container, we specified that ./exports on our machine should map to the container internal directory /opt/keycloak/data. With this definition, we can target this internal directory and the generated files will be available in our machine, at the ./exports directory.
4. Running the export command
/opt/keycloak/bin/kc.sh export --dir /opt/keycloak/data --realm realmName
5. The exported data
Finally, we can access the exported data. The realm and user data are in seperate files. You can change this setting by referring to the section: Configuring how users are exported
Happy Coding !!!
Member discussion