2
1

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?

More than 1 year has passed since last update.

devcontainer + doker-compose環境でkeycloakでrealmをインポートする

Posted at

KeycloakのVersion 18を利用しています。

devcontainerでkeycloakを使いたかったので、devcontainer起動時にexportしておいたrealmのimportをしようとしたところ、調べて出てきたKEYCLOAK_IMPORTKC_IMPORT が動きませんでした。

調べてみると以下のような情報が出てきました。上記の変数は利用できなくなっているようです。

情報を整理したところ以下の方法で実現できました。

Export

以下のコマンドでexportするとユーザも含めてrealmをexportできます。

/opt/keycloak/bin/kc.sh export --realm myrealm --users realm_file --file /tmp/realm.json

自動Import

devcontainerのworkspaceに ./keycloak というディレクトリを作って上記でexportしたrealm.jsonを配置して以下の定義からdevcontainerを起動します。

  • ./keycloak/opt/keycloak/data/import にマウントします
  • start-devに --import-realm の引数を付けます
  keycloak:
    image: quay.io/keycloak/keycloak:18.0.2
    restart: unless-stopped
    environment:
      KEYCLOAK_ADMIN: admin
      KEYCLOAK_ADMIN_PASSWORD: admin
    volumes:
      - ${LOCAL_WORKSPACE_FOLDER:-./keycloak}:/opt/keycloak/data/import:ro
    command: ["start-dev","--import-realm"]
    networks:
      - datacatalog-network

コンテナのログを確認するとインポートされていることが確認できます。

keycloak_1  | 2024-03-05 14:04:47,840 INFO  [org.keycloak.services] (main) KC-SERVICES0050: Initializing master realm
keycloak_1  | 2024-03-05 14:04:49,964 INFO  [org.keycloak.services] (main) KC-SERVICES0004: Imported realm myrealm from file /opt/keycloak/bin/../data/import/realm.json.
2
1
0

Register as a new user and use Qiita more conveniently

  1. You get articles that match your needs
  2. You can efficiently read back useful information
  3. You can use dark theme
What you can do with signing up
2
1

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?