Open Source Identity and Access Management for Modern Applications and Services.
Add authentication to applications and secure services with minimum fuss. No need to deal with storing users or authenticating users. It's all available out of the box.
You'll even get advanced features such as User Federation, Identity Brokering and Social Login.
After configuring Keycloak you can export the configuration to a JSON file so that it can be used to initialize a new Keycloak instance. If you use the UI to export it will not contain all the necessary information and settings, thus the need for this CLI option.
More information here.
Once the keycloak container is running, ssh into it and execute the following commands;
docker psdocker exec -it {ContainerID} bashdocker exec -it tno-keycloak bash
# Old jboss image
/opt/jboss/keycloak/bin/standalone.sh \
-Dkeycloak.migration.action=export \
-Dkeycloak.migration.provider=singleFile \
-Dkeycloak.migration.realmName=tno \
-Dkeycloak.migration.file=/tmp/realm-export.json \
-Dkeycloak.migration.usersExportStrategy=REALM_FILE \
-Dkeycloak.migration.strategy=OVERWRITE_EXISTING \
-Djboss.http.port=8888 \
-Djboss.https.port=9999 \
-Djboss.management.http.port=7777
# New Keycloak image
/opt/keycloak/bin/kc.sh \
export --file /opt/keycloak/data/import/realm-export.json --realm tnoIf you have issues with the automatic import you can manually import the realm. To import a previously exported realm configuration execute the following command;
docker exec -it keycloak bash
# Old jboss image
/opt/jboss/keycloak/bin/standalone.sh \
-Djboss.socket.binding.port-offset=100 \
-Dkeycloak.migration.action=import \
-Dkeycloak.profile.feature.scripts=enabled \
-Dkeycloak.profile.feature.upload_scripts=enabled \
-Dkeycloak.migration.provider=singleFile \
-Dkeycloak.migration.file=/tmp/realm-export.json
# New Keycloak image
/opt/keycloak/bin/kc.sh \
import --file /opt/keycloak/data/import/realm-export.jsonor
# Old jboss image
$ docker run -e KEYCLOAK_USER=<USERNAME> -e KEYCLOAK_PASSWORD=<PASSWORD> \
-e KEYCLOAK_IMPORT=/tmp/example-realm.json -v /tmp/example-realm.json:/tmp/example-realm.json jboss/keycloakNote that the import script has hardcoded passwords, which will override whatever password you have in your .env.
user: keycloak, pwd: password
- Stop Keycloak
$ docker-compose stop keycloak keycloak-db - Remove containers
$ docker rm keycloakand$ docker rm keycloak-db - Remove volume
$ docker volume rm tno_keycloak-db-data - Build Keycloak
$ docker-compose build keycloak - Make sure your
.envcomments out this line# KEYCLOAK_IMPORT=/tmp/realm-export.json - Start Keycloak
$ docker-compose up -d keycloak - Open Keycloak in your browser http://keycloak:8080, verify the
masterrealm is there. It will take a minute to initialize. - Bash into the Keycloak docker container
$ docker exec -it keycloak bash - Run the import standalone.sh script above. It will hang on this line -
18:30:37,822 WARN [org.keycloak.common.Profile] (ServerService Thread Pool -- 68) Preview feature enabled: scripts. Let it run for a minute. - Press
ctrl+cand exit thebash - Restart Keycloak
$ docker-compose restart keycloak - Open Keycloak in your browser http://keycloak:8080, verify the
tnoream is there. It will take a minute to initialize.