skip to Main Content

I tried everything I could find in other related posts but Keycloak admin console that is running on a local docker image is not loading.

There is an infinite spinner with the text: Loading the Admin UI

I am guessing somewhere in my docker-compose.yml file is an error that I can not find.

If someone had a similar issue, please help me solve it.

version: '3'
services:
  nginx:
    image: nginx:latest
    ports:
      - "80:80"
    volumes:
      - "./docker-configs/nginx.conf:/etc/nginx/conf.d/default.conf"
      - ".:/app:cached"
  php:
    build:
      context: ./docker-configs/php
    volumes:
      - "./docker-configs/php/php.ini:/usr/local/etc/php/conf.d/php.ini"
      - ".:/app:cached"
    environment:
      PHP_IDE_CONFIG: "serverName=Docker"

  database:
    image: mysql:8.1.0
    platform: linux/amd64
    environment:
      MYSQL_ROOT_PASSWORD: root
      MYSQL_DATABASE: best_db
      MYSQL_PASSWORD: root
    ports:
      - '3306:3306'
    volumes:
      - ./mysql-data:/var/lib/mysql

  keycloak:
    image: quay.io/keycloak/keycloak:22.0
    # restart: unless-stopped
    environment:
      KC_HTTP_ENABLED: 'true'
      KEYCLOAK_ADMIN: admin
      KEYCLOAK_ADMIN_PASSWORD: admin
      KC_DB_URL_HOST: database
      KC_DB_URL_DATABASE: keycloak
      KC_DB_USERNAME: keycloak
      KC_DB_PASSWORD: keycloak
      KC_HOSTNAME: keycloak
      KC_DB_URL_PORT: 3306
      KC_HOSTNAME_STRICT: 'false'
      KC_HOSTNAME_STRICT_HTTPS: 'false'
      KC_TRANSACTION_XA_ENABLED: 'false'
    command: '-v start-dev --import-realm'
    depends_on:
      - database
    ports:
      - '8080:8080'
      - '8443:8443'

2

Answers


  1. Keycloak needs to be able to access the database.
    This error isn’t super obvious because the logs don’t give you a lot of information.

    However if you adjust to match the user/password you create in the database part of your yaml to the user/password you’re using in the keycloak part, you’ll be fine.

    So it needs to look something like

      database:
        image: mysql:8.1.0
        platform: linux/amd64
        environment:
          MYSQL_ROOT_PASSWORD: root
          MYSQL_DATABASE: keycloak
          MYSQL_USER: keycloak
          MYSQL_PASSWORD: password
        ports:
          - '3306:3306'
        volumes:
          - ./mysql-data:/var/lib/mysql
    
      keycloak:
        image: quay.io/keycloak/keycloak:22.0
        # restart: unless-stopped
        environment:
          KEYCLOAK_LOGLEVEL: DEBUG
          KC_HTTP_ENABLED: 'true'
          KEYCLOAK_ADMIN: admin
          KEYCLOAK_ADMIN_PASSWORD: admin
          KC_DB_URL_HOST: database
          KC_DB_URL_DATABASE: keycloak
          KC_DB_USERNAME: keycloak
          KC_DB_PASSWORD: password
          KC_HOSTNAME: keycloak
          KC_DB_URL_PORT: 3306
          KC_HOSTNAME_STRICT: 'false'
          KC_HOSTNAME_STRICT_HTTPS: 'false'
          KC_TRANSACTION_XA_ENABLED: 'false'
        command: '-v start-dev '
        depends_on:
          - database
        ports:
          - '8080:8080'
          - '8443:8443'
    
    Login or Signup to reply.
  2. I had to comment – KC_HOSTNAME option out in docker-compose file and it worked after that. (Based on the hint here: https://www.reddit.com/r/homelab/comments/yzn476/keycloak_in_docker_endless_look_at_admin_console/ ) Can’t explain WHY…

    version: '3'
    services:
      postgresql:
        image: postgres:16
        ports:
          - "5432:5432"
        environment:
          - POSTGRES_USER=keycloak
          - POSTGRES_DB=keycloak
          - POSTGRES_PASSWORD=keycloak
        volumes:
          - '/home/ubuntu/docker/keycloak/postgresql_data:/var/lib/postgresql/data'
        networks:
          keycloak:
    
      keycloak:
        image: quay.io/keycloak/keycloak:22.0.3
        ports:
          - "8080:8080"
        restart: always
        command: start
        depends_on:
          - postgresql
        environment:
          - KC_PROXY_ADDRESS_FORWARDING=true
          - KC_HOSTNAME_STRICT=false
    #      - KC_HOSTNAME=xxxxx:8080
          - KC_PROXY=edge
          - KC_HTTP_ENABLED=true
          - KC_HOSTNAME_STRICT_HTTPS=false
          - DB=keycloak
          - DB_URL='jdbc:postgresql://postgres:5432/postgresql?ssl=allow'
          - DB_USERNAME=keycloak
          - DB_PASSWORD=keycloak
          - KEYCLOAK_ADMIN=admin
          - KEYCLOAK_ADMIN_PASSWORD=password
        networks:
          proxy:
          keycloak:
        labels:
          - "traefik.enable=true"
          - "traefik.http.routers.keycloak.entrypoints=http"
          - "traefik.http.routers.keycloak.rule=Host(`xxxxx`)"
          - "traefik.http.middlewares.keycloak-https-redirect.redirectscheme.scheme=https"
          - "traefik.http.routers.keycloak.middlewares=keycloak-https-redirect"
          - "traefik.http.routers.keycloak-secure.entrypoints=https"
          - "traefik.http.routers.keycloak-secure.rule=Host(`xxxxx`)"
          - "traefik.http.routers.keycloak-secure.tls=true"
          - "traefik.http.routers.keycloak-secure.service=keycloak"
          - "traefik.http.services.keycloak.loadbalancer.server.port=8080"
          - "traefik.docker.network=proxy"
    
    networks:
      proxy:
    #    external: true
      keycloak:
    
    Login or Signup to reply.
Please signup or login to give your own answer.
Back To Top
Search