The command
/opt/keycloak/bin/kc.sh -v start-dev
–import-realm
is only to import reamls on startup, but not for users.
I would create some default users on startup. Is this only possible with the import command “/opt/keycloak/bin/kc.sh import --dir /opt/keycloak/data/import/ --override true” ?
I would prefer startup and create users in one step, how i can do wiht the --import-realm option.
ok, thank you for the hint.
the problem ist, it’s not possible to export the reamls and user to a file and then inport the file.
If i do that, there are more than one realm in the file (master and mine) and kc throws a exeption while importing a file with more than one realm!
Caused by: com.fasterxml.jackson.databind.exc.MismatchedInputException: Cannot deserialize value of type org.keycloak.representations.idm.RealmRepresentation from Array value (token JsonToken.START_ARRAY)
the only way was to export the realms and users to different files and the merge the realm and users togehter…
Of course it’s possible to export only one specific realm, just read the docs properly: Importing and Exporting Realms - Keycloak
(I do this regulary for some test- & dev-environments)
After spent many hours to do that, it was not possible to do that on startup. There was a very strange behavior on Keycloak. After i imported the same configuration before start, then it was working! I think there are some bugs on import configuration on startup time.
In my case, I forgot to rebuild Keycloak image for the container. So that updated realm.json file was not copied to /opt/keycloak/data/import/ and script was still using the old file. After rebuild --import-realm flag did it’s job and all data was imported, including users. Maybe it will help.