Cant import realm using Docker Image

Late answer: If one has clients with “Authorization Enabled”, the upload_scripts feature must be enabled, else I have no problems importing the realm.

In my case, using realm-export.json didn’t work. I looked through the docs and there is a strict naming convention to follow <your-realm-name>-realm.json. Passing the environment var with the correct name did the trick.

Hi,
In my case I have removed the "policies": [] part which was in the the exported realm.json file, and my problem has been solved.

"policies": [
          {
            "id": "12345676-fbf8-4d59-911b-c4678621daac",
            "name": "Default Policy",
            "description": "A policy that grants access only for users within this realm",
            "type": "js",
            "logic": "POSITIVE",
            "decisionStrategy": "AFFIRMATIVE",
            "config": {
              "code": "// by default, grants any permission associated with this policy\n$evaluation.grant();\n"
            }
          },
          {
            "id": "12345678-7abf-4083-9754-7bbf59bdea5b",
            "name": "Default Permission",
            "description": "A permission that applies to the default resource type",
            "type": "resource",
            "logic": "POSITIVE",
            "decisionStrategy": "UNANIMOUS",
            "config": {
              "defaultResourceType": "urn:ssoClient-customerCareGUI:resources:default",
              "applyPolicies": "[\"Default Policy\"]"
            }
          }
        ],

2 Likes

Accepted answer, thank you !!

Hey everyone! I try to import realm on startup by using –import-realm flag. However I received error

ERROR [org.keycloak.quarkus.runtime.cli.ExecutionExceptionHandler] (main) ERROR: Cannot read the array length because “local8” is null

It’s so strange because I tried import same file in UI and test based on KeycloakContainer and it work!

My Dockerfile:

FROM quay.io/keycloak/keycloak:21.0.0

ADD ./data/my-realm.json /opt/keycloak/data/import

USER root

RUN /opt/keycloak/bin/kc.sh build

# from base image

ENV KEYCLOAK_ADMIN="admin"
ENV KEYCLOAK_ADMIN_PASSWORD="admin"

EXPOSE 8080
EXPOSE 8443

ENTRYPOINT [ "/opt/keycloak/bin/kc.sh" ]

CMD ["start-dev --import-realm"]

realm-file located here https://drive.google.com/file/d/1w8D0a88ImWPxlkZs3Md0AGHDp9-s3hJl/view?usp=sharing

Somebody know how to fix it?

SOLVED! I lost slash when add file to image

ADD ./data/my-realm.json /opt/keycloak/data/import → ADD ./data/my-realm.json /opt/keycloak/data/import/