p2-inc / phasetwo-containers

Docker image for Phase Two Keycloak distribution
Other
65 stars 21 forks source link

Postgres docker-compose example data not persistant #52

Closed mihha closed 3 months ago

mihha commented 3 months ago

Hi!

I am using your Postgres docker compose example with slight changes for volume tags

version: '3'

services:
  postgres:
    image: postgres:11
      # image: postgres
    volumes:
      - ./postgres_data:/var/lib/postgresql/data
    environment:
      POSTGRES_DB: keycloak
      POSTGRES_USER: keycloak
      POSTGRES_PASSWORD: password
    ports:
      - 5433:5432
  keycloak:
    image: quay.io/phasetwo/phasetwo-keycloak:latest
    environment:
      PROXY_ADDRESS_FORWARDING: 'true'
      KEYCLOAK_PRODUCTION: true
      KEYCLOAK_USER: admin
      KEYCLOAK_PASSWORD: password
      KEYCLOAK_ADMIN: admin
      KEYCLOAK_ADMIN_PASSWORD: password
      KC_DB_VENDOR: POSTGRES
      KC_DB_URL_HOST: postgres
      KC_DB_URL_DATABASE: keycloak
      KC_DB_SCHEMA: public
      KC_DB_USERNAME: keycloak
      KC_DB_PASSWORD: password
      KC_HOSTNAME_URL: https://auth.MY_DOMAIN.net
      KC_HOSTNAME_ADMIN_URL: https://auth.MY_DOMAIN.net
      KC_HOSTNAME_PATH: /
      KC_HOSTNAME_STRICT: 'false'
      KC_HTTP_ENABLED: 'true'
      KC_PROXY: 'edge'
      KC_PROXY_HEADERS: 'xforwarded'
      KC_LOG_LEVEL: INFO
    entrypoint: ["/opt/keycloak/bin/kc.sh", "start", "--spi-email-template-provider=freemarker-plus-mustache", "--spi-email-template-freemarker-plus-mustache-enabled=true", "--spi-theme-cache-themes=false"]
    restart: unless-stopped
    ports:
      - 8080:8080
    depends_on:
      - postgres

With this docker compose file, when I stop and start docker again, data in Keycloak is lost and everything is reset to the initial values

I can't figure out what I am doing wrong here

I would be really grateful if someone could check this and point me into the right direction

Thank you all for your attention!

Regards, Igor

xgp commented 3 months ago

Probably need to do something like this:

version: '3'

volumes:
  postgres_data:
    driver: local

services:
  postgres:
    image: postgres:11
      # image: postgres
    volumes:
      - postgres_data:/var/lib/postgresql/data
    environment:
      POSTGRES_DB: keycloak
      POSTGRES_USER: keycloak
      POSTGRES_PASSWORD: password
    ports:
      - 5433:5432
  keycloak:
    image: quay.io/phasetwo/phasetwo-keycloak:latest
    environment:
      PROXY_ADDRESS_FORWARDING: 'true'
      KEYCLOAK_PRODUCTION: true
      KEYCLOAK_USER: admin
      KEYCLOAK_PASSWORD: password
      KEYCLOAK_ADMIN: admin
      KEYCLOAK_ADMIN_PASSWORD: password
      KC_DB_VENDOR: POSTGRES
      KC_DB_URL_HOST: postgres
      KC_DB_URL_DATABASE: keycloak
      KC_DB_SCHEMA: public
      KC_DB_USERNAME: keycloak
      KC_DB_PASSWORD: password
      KC_HOSTNAME_URL: https://auth.MY_DOMAIN.net
      KC_HOSTNAME_ADMIN_URL: https://auth.MY_DOMAIN.net
      KC_HOSTNAME_PATH: /
      KC_HOSTNAME_STRICT: 'false'
      KC_HTTP_ENABLED: 'true'
      KC_PROXY: 'edge'
      KC_PROXY_HEADERS: 'xforwarded'
      KC_LOG_LEVEL: INFO
    entrypoint: ["/opt/keycloak/bin/kc.sh", "start", "--spi-email-template-provider=freemarker-plus-mustache", "--spi-email-template-freemarker-plus-mustache-enabled=true", "--spi-theme-cache-themes=false"]
    restart: unless-stopped
    ports:
      - 8080:8080
    depends_on:
      - postgres

Can you try that @mihha and PR if that works for you?

mihha commented 3 months ago

I can, but I prefer to have my volume data bind to the specific folder and not the one docker is using for the volumes

This makes backup process easier and consistent

I see no difference and there shouldn't be any difference between those two

mihha commented 3 months ago

I don't understand why is this closed if it is not resolved

xgp commented 3 months ago

I gave you an option that works. You expressed a preference for how you want it to work. Feel free to figure out what works for you and PR it if you think it will help others.