1

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.

1 Answer 1

1

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

Sign up to request clarification or add additional context in comments.

8 Comments

Is It possible to do not use the postgres Image/container , and just pass the Postgres ConnectionURL
Of course it is possible, make sure database user exists for keycloak.
Can you share the yaml file format for that we want only keycloak container and external postgres Database connected keycloak using only Connection URL
Just remove everything nested under postgres
Tried below version: '3' services: keycloak: image: quay.io/keycloak/keycloak:latest environment: DB_VENDOR: POSTGRES DB_ADDR: localhost DB_PORT: 5432 DB_DATABASE: keycloakLocal DB_USER: postgres DB_SCHEMA: public DB_PASSWORD: Adm!n@123 KEYCLOAK_USER: localkeycloak KEYCLOAK_PASSWORD: local ports: - 8080:8080 removed all postgres related data just passed environment variables also passed IP address instead of localhost still not getting connected
|

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.