Hi,
Excuse me if this has been asked before, I’ve Googled and troubleshooted a lot but couldn’t figure it out myself. I have some issues with data persistence in a Dockerized Keycloak instance and I read that this is solved by using an external database with persistent volumes (in my case a bind mount) as opposed to the default included H2 database. The problem is, my data doesn’t seem to survive after a container removal. I tried getting some clues with:
docker logs keycloak, docker inspect keycloak, docker exec -it keycloak /bin/bash (followed by: kc.sh show-config) but no luck.
Below you’ll see my Docker Compose file. I’m wondering if my database config in the compose file is wrong because something noticeable is: when I change my database address configuration for troubleshooting purposes:
DB_ADDR=postgresql
to something gibberish
DB_ADDR=asjlkasfasffga
the Keycloak container starts without issues but more important, it doesn’t output any errors regarding the database connection. Is this expected? I’m was expecting to see something along the lines of “could not connect to db” or similar. Further more, the Postgres bind mount does exist and gets filled with (default) data when the Postgres container is started. Postgres also doesn’t throw out any errors when it’s started.
Can anyone spot any errors in my compose file?
services:
postgresql:
image: postgresql:latest
environment:
- POSTGRES_USER=keycloakdbuser
- POSTGRES_PASSWORD=password
- POSTGRES_DB=keycloak
volumes:
- /opt/project/postgresql:/var/lib/postgresql/data
networks:
- keycloaknet
keycloak:
image: quay.io/keycloak/keycloak:latest
ports:
- 8080:8080
environment:
- KEYCLOAK_ADMIN=keycloakadmin
- KEYCLOAK_ADMIN_PASSWORD=adminpassword
- DB_DATABASE=keycloak
- DB_USER=keycloakdbuser
- DB_PASSWORD=password
- DB_ADDR=postgresql
- DB_VENDOR=postgres
entrypoint: '/opt/keycloak/bin/kc.sh --spi-login-protocol-openid-connect-legacy-logout-redirect-uri=true --spi-theme-static-max-age=-1 --spi-theme-cache-themes=false --spi-theme-cache-templates=false start --hostname hostname.tld'
networks:
- keycloaknet
depends_on:
- postgresql
keycloaknet:
driver: bridge
name: keycloaknet