sameer
sameer

Reputation: 23

What is the keycloak docker compose Yaml file format for external postgres db connection URL

I need to setup the Keycloak docker server with the External postgres Database connection URL. Here's my current yaml file content which is working with POstgres docker container image as mentioned

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

I checked the official documentation for passing external DB connection URL. But exactly didn't get what changes will be needed in YAML file ref: https://hub.docker.com/r/jboss/keycloak/

I tried removing the Postgres and depends_on section from services and passed the Database connection details in Kecyloak environment section in yaml but it did not worked for me

Can anyone suggest the correct YAML file changes to use PostgresDB connection URL

Thank You.

Upvotes: 1

Views: 4904

Answers (1)

Ghokun
Ghokun

Reputation: 3465

Docker containers can see each other by their service name, so here service name postgres is actually the connection url for keycloak container.

version: '3'

volumes:
  postgres_data:
    driver: local

services:
  postgres: # Service name 
    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 # <<< This is the address, change it to your external db ip/domain
      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

Upvotes: 1

Related Questions