Docker-compose with keycloak and postgres

Hi everyone,
Has anyone (or can make) dockrer-compose file which run:

  • postgres with custom schema (for example keycloak)
  • keycloak witch use postgres database with schema keycloak?

Here’s mine. I don’t really know what you mean by a “custom schema”. Keycloak will create the database schema in the database you give it when it starts up the first time.

version: '3'

volumes:
  postgres_data:
    driver: local

services:
  postgres:
    image: postgres:11
    volumes:
      - postgres_data:/var/lib/postgresql/data
    environment:
      POSTGRES_DB: keycloak
      POSTGRES_USER: keycloak
      POSTGRES_PASSWORD: password
    ports:
      - 5433:5432
  keycloak:
    image: jboss/keycloak:latest
    environment:
      DB_VENDOR: POSTGRES
      DB_ADDR: postgres
      DB_DATABASE: keycloak
      DB_USER: keycloak
      DB_SCHEMA: public
      DB_PASSWORD: password
      KEYCLOAK_USER: admin
      KEYCLOAK_PASSWORD: password
      KEYCLOAK_LOGLEVEL: DEBUG
      ROOT_LOGLEVEL: DEBUG
    ports:
      - 8080:8080
      - 8443:8443
    depends_on:
      - postgres

[quote=“xgp, post:2, topic:8964”]
Here’s mine. I don’t really know what you mean by a “custom schema”. Keycloak will create the database schema in the database you give it when it starts up the first time.


I would like keycloak doesn’t use public database schema, but keycloak_schema for example.
Does this docker-compose work for you? I ask, becouse doesn’t work for me (stoped with code 1).

Yes. It works fine for me.

I haven’t used a different schema name, but you can apparently use DB_SCHEMA according to the keycloak docker docs: Docker Hub

I know, but I think you need to create it first database.

You can add an init script to your postgres volumes to create the schema you want

postgres:
  image: postgres:11
  volumes:
    - ./init.sql:/docker-entrypoint-initdb.d/init.sql