Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

"You need local access to create the initial admin user" error while keycloak startup in docker

While starting keycloak server on docker, I am getting this error: "You need local access to create the initial admin user". But running it locally, it's working fine.

Another thing is that if I want to use Postgres db instead of embedded H2 db then should I create tables to store user, clients and scope, etc? If yes how can I get db structure for all tables?

You need local access to create the initial admin user

like image 292
gar Avatar asked Jan 24 '20 07:01

gar


2 Answers

You can let the container create the admin user by providing the environment variables KEYCLOAK_USER and KEYCLOAK_PASSWORD:

docker run -e KEYCLOAK_USER=<USERNAME> -e KEYCLOAK_PASSWORD=<PASSWORD> jboss/keycloak

Or add the account to an existing container( Service or container restart required afterwards) with:

docker exec <CONTAINER> /opt/jboss/keycloak/bin/add-user-keycloak.sh -u <USERNAME> -p <PASSWORD>

And either restart container docker restart <container>

Or restart the service (@Madeo's answer)

docker exec -it <container> /opt/jboss/keycloak/bin/jboss-cli.sh --connect --command=:reload

The above commands come from the Keycloak Docker image page on Docker Hub.

Regarding your database question, you don't have to provide the tables by hand. You can refer to chapter 6 (§6.4, §6.5) of the Keycloak documentation for the details of how to configure a PostgreSQL DB.

like image 132
Pierre Avatar answered Sep 17 '22 16:09

Pierre


None of the tips above worked. Finally I use Environment Variables:

KEYCLOAK_ADMIN: admin
KEYCLOAK_ADMIN_PASSWORD: admin

The full code of the docker-compose.yml:

version: '3'

volumes:
  postgres_data:
      driver: local

services:
  postgres:
      image: postgres
      volumes:
        - postgres_data:/var/lib/postgresql/data
      environment:
        POSTGRES_DB: keycloak
        POSTGRES_USER: keycloak
        POSTGRES_PASSWORD: password
  keycloak:
      image: quay.io/keycloak/keycloak:17.0.1
      environment:
        DB_VENDOR: POSTGRES
        DB_ADDR: postgres
        DB_DATABASE: keycloak
        DB_USER: keycloak
        DB_SCHEMA: public
        DB_PASSWORD: password
        KEYCLOAK_USER: admin
        KEYCLOAK_PASSWORD: admin
        KEYCLOAK_ADMIN: admin
        KEYCLOAK_ADMIN_PASSWORD: admin
      entrypoint: ["/opt/keycloak/bin/kc.sh", "start-dev"]
      ports:
        - 8080:8080
      depends_on:
        - postgres
like image 38
Hernaldo Gonzalez Avatar answered Sep 18 '22 16:09

Hernaldo Gonzalez