7

I'm using a Dockerfile for create a custom image of Keycloak as follows:

FROM quay.io/keycloak/keycloak:18.0.2 as builder

ENV KC_HEALTH_ENABLED=true
ENV KC_METRICS_ENABLED=true
ENV KC_DB=postgres
# Install custom providers
RUN curl -sL https://github.com/aerogear/keycloak-metrics-spi/releases/download/2.5.3/keycloak-metrics-spi-2.5.3.jar -o /opt/keycloak/providers/keycloak-metrics-spi-2.5.3.jar
RUN /opt/keycloak/bin/kc.sh build

FROM quay.io/keycloak/keycloak:18.0.2
COPY --from=builder /opt/keycloak/ /opt/keycloak/
WORKDIR /opt/keycloak
ENTRYPOINT ["/opt/keycloak/bin/kc.sh", "start"]

and whit this docker-compose I am able to run Keycloak:

version: "3.9"
services:

  keycloak_db:
    image: postgres
    environment:
      - POSTGRES_USER=$DB_USER
      - POSTGRES_PASSWORD=$DB_PASS
      - POSTGRES_DB=$DB_NAME
      - IGNORE_INIT_HOOK_LOCKFILE=true
    volumes:
      - ./db/:/docker-entrypoint-initdb.d/
    ports:
      - ${DB_EXTERNAL_PORT:-15432}:5432

  keycloak:
    container_name: keycloak
    # image: quay.io/keycloak/keycloak:18.0.1
    image: keycloak
    ports:
      - "${KEYCLOAK_EXTERNAL_PORT:-18180}:8080"
    environment:
      - KEYCLOAK_ADMIN=${KEYCLOAK_USER}
      - KEYCLOAK_ADMIN_PASSWORD=${KEYCLOAK_PASSWORD}
      - KC_DB=postgres
      - KC_DB_URL_HOST=$DB_HOST
      - KC_DB_URL_PORT=5432
      - KC_DB_URL_DATABASE=$DB_NAME
      - KC_DB_SCHEMA=$KEYCLOAK_SCHEMA
      - KC_DB_USERNAME=$DB_USER
      - KC_DB_PASSWORD=$DB_PASS
      - KC_HTTP_ENABLED=true
      - KC_HOSTNAME=localhost
      - KC_HOSTNAME_ADMIN=localhost
      - KC_HOSTNAME_PORT=80
      - KC_HOSTNAME_STRICT_BACKCHANNEL=true
      - KC_HOSTNAME_STRICT_HTTPS=false
      - KC_PROXY=edge
      - KC_PROXY_ADDRESS_FORWARDING=true
      - KC_KEYCLOAK_FRONTEND_URL=http://localhost:18180/
      - KC_KEYCLOAK_URL=http://localhost:18180/
      # - KC_LOG_LEVEL=debug
    depends_on:
      - keycloak_db

I can see the Keycloak homepage: enter image description here

But when I try to go to the admnistration console I see a blank page: enter image description here


What goes wrong?




EDIT: I upgraded Keycloak version to 18.0.2.

And if I use KC_FEATURES=admin2 as further environment variable I can see something, but still not the admin console:

enter image description here


EDIT 2: If I add ENV KC_FEATURES=token-exchange in Dockerfile for the builder, I can see the login page:

enter image description here

But after the log in... always a blank page:

enter image description here

Kambei
  • 458
  • 9
  • 23
  • 1
    Experiencing the same issue.. When I inspect the page and look at Network I see it tries to do a http call instead of https which we're using.. Hopefully someone knows what is going wrong here – Lucas Scheepers Jul 07 '22 at 10:42
  • 1
    Had similar issue with Keycloak admin ui and thanks to this and was able to determine the cause. – Laurenzo Sep 20 '22 at 05:27

3 Answers3

3

Your KC_HOSTNAME_PORT is probably incorrect. If KEYCLOAK_EXTERNAL_PORT is set to 18180 and you are not behind a reverse proxy you should set KC_HOSTNAME_PORT to 18180.

This configuration is working:

 keycloak:
    container_name: keycloak
    # image: quay.io/keycloak/keycloak:18.0.1
    image: keycloak
    ports:
      - "${KEYCLOAK_EXTERNAL_PORT:-18180}:8080"
    environment:
      - KEYCLOAK_ADMIN=${KEYCLOAK_USER}
      - KEYCLOAK_ADMIN_PASSWORD=${KEYCLOAK_PASSWORD}
      - KC_DB=postgres
      - KC_DB_URL_HOST=$DB_HOST
      - KC_DB_URL_PORT=5432
      - KC_DB_URL_DATABASE=$DB_NAME
      - KC_DB_SCHEMA=$KEYCLOAK_SCHEMA
      - KC_DB_USERNAME=$DB_USER
      - KC_DB_PASSWORD=$DB_PASS
      - KC_HTTP_ENABLED=true
      - KC_HOSTNAME=localhost
      - KC_HOSTNAME_ADMIN=localhost
      - KC_HOSTNAME_PORT=18080
      - KC_HOSTNAME_STRICT_BACKCHANNEL=true
      - KC_HOSTNAME_STRICT_HTTPS=false
      - KC_PROXY=edge
      - KC_PROXY_ADDRESS_FORWARDING=true
      - KC_KEYCLOAK_FRONTEND_URL=http://localhost:18180/
      - KC_KEYCLOAK_URL=http://localhost:18180/
      # - KC_LOG_LEVEL=debug
    depends_on:
      - keycloak_db
F. Salvini
  • 335
  • 2
  • 9
0

So we found that it was the nginx ingress controller causing a lot of issues. Moving to haproxy resolved this problem. As well, make sure you are interfacing with the ingress controller over https or that may cause issues with keycloak.

  annotations:
        kubernetes.io/ingress.class: haproxy
  ...
Carter
  • 1,184
  • 11
  • 5
0

https://github.com/Muhammed-sidhin/Keycloak

This is official Keycloak Docker image for development. It's based on Keycloak Official Docker Image, starting with keycloak-15

This configuration is working