Importing keycloak configuration files while using docker-compose
Explanation
First you need to copy the file into your container before you can import it into Keycloak. You could place your realm-export.json
in a folder next to the docker-compose.yml
, lets say we call it imports
. This can be achieved using volumes:
. Once the file has been copied into the container then you can use command:
as you were before, pointing at the correct file within the container.
File Structure
/your_computer/keycloak_stuff/
|-- docker-compose.yml
|-- imports
-> realm-export.json
Docker-Compose
This is how the docker-compose.yml
should look with the changes:
postgres: image: postgres volumes: - postgres_data:/var/lib/postgresql/data environment: POSTGRES_DB: keycl0ak POSTGRES_USER: keycl0ak POSTGRES_PASSWORD: password ports: - 5431:5431 keycloak: build: context: services/keycloak volumes: - ./imports:/opt/jboss/keycloak/imports command: - "-b 0.0.0.0 -Dkeycloak.import=/opt/jboss/keycloak/imports/realm-export.json" environment: DB_VENDOR: POSTGRES DB_ADDR: postgres DB_DATABASE: keycl0ak DB_USER: keycl0ak DB_PASSWORD: password KEYCLOAK_USER: administrat0r KEYCLOAK_PASSWORD: asc88a8c0ssssqs ports: - 8080:8080 depends_on: - postgresvolumes: postgres_data: driver: local
To wrap up the answer of @JesusBenito and @raujonas, the docker-compose could be changed, so that you make use of the keyloak environment KEYCLOAK_IMPORT:
keycloak: volumes: - ./imports:/opt/jboss/keycloak/imports # command: not needed anymore # - "-b 0.0.0.0 -Dkeycloak.import=/opt/jboss/keycloak/imports/realm-export.json" environment: KEYCLOAK_IMPORT: /opt/jboss/keycloak/imports/realm-export.json -Dkeycloak.profile.feature.upload_scripts=enabled DB_VENDOR: POSTGRES DB_ADDR: postgres DB_DATABASE: keycl0ak DB_USER: keycl0ak DB_PASSWORD: password KEYCLOAK_USER: administrat0r KEYCLOAK_PASSWORD: asc88a8c0ssssqs