I cannot start keycloak container using ansible and docker-compose. I'am getting error: User with username 'admin' already added to '/opt/jboss/keycloak/standalone/configuration/keycloak-add-user.json'
I have 3 ansible jobs:
Create netwrok:
- name: Create a internal network   docker_network:     name: internal Setup postgres:
- name: "Install Postgres"   docker_compose:     project_name: posgressdb     restarted: true     pull: yes     definition:       version: '2'       services:         postgres:           image: postgres:12.1           container_name: postgres           restart: always           env_file:             - /etc/app/db.env           networks:             - internal           volumes:             - postgres-data:/var/lib/postgresql/data             - /etc/app/createdb.sh:/docker-entrypoint-initdb.d/init-app-db.sh           ports:             - "5432:5432"       volumes:         postgres-data:       networks:         internal:           external:             name: internal Create keycloak container:
- name: Install keycloak   docker_compose:     project_name: appauth     restarted: true     pull: yes     definition:       version: '2'       services:         keycloak:           image: jboss/keycloak:8.0.1           container_name: keycloak           restart: always           environment:             - DB_VENDOR=POSTGRES             - DB_ADDR=postgres             - DB_PORT=5432             - DB_SCHEMA=public             - DB_DATABASE=keycloak             - DB_USER=keycloak             - DB_PASSWORD=keycloak             - KEYCLOAK_USER=admin             - KEYCLOAK_PASSWORD=admin           networks:             - internal       networks:         internal:           external:             name: internal  Does anyone have any idea why I get this error?
EDIT
If I downgrade keycloak to version 7 it starts normally!
Just to clarify the other answers. I had the same issue. What helped for me was:
comment out the two relevant lines
version: "3"  services:   keycloak:     image: quay.io/keycloak/keycloak:latest     environment:       # KEYCLOAK_USER: admin       # KEYCLOAK_PASSWORD: pass       ... start all containers;
comment back in the two lines from above
version: "3"  services:   keycloak:     image: quay.io/keycloak/keycloak:latest     environment:       KEYCLOAK_USER: admin       KEYCLOAK_PASSWORD: pass       ... This time (and subsequent times) it worked. Keycloak was running and the admin user was registered and working as expected.
This happens when Keycloak is interrupted during boot. After this, command which attempts to add admin user starts to fail. In Keycloak 7 this wasn't fatal, but in 8.0.1 this line was added to /opt/jboss/tools/docker-entrypoint.sh which aborts the entire startup script:
set -eou pipefail Related issue: https://issues.redhat.com/browse/KEYCLOAK-12896
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With