Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to take db backup in keycloak docker container

I installed keycloak using docker for my django project

docker run -p 8080:8080 -e KEYCLOAK_USER=admin -e KEYCLOAK_PASSWORD=admin jboss/keycloak

now everything is working fine but now i want take backup of keycloak db in docker but i do not know which database installed by default inside keycloak docker container,so how to take backup and restore data, i was using $ sudo docker exec -it 35ba690a68fd /bin/bash this command to interact with container, please any suggestion. i am using redhat Linux

like image 402
karnataka Avatar asked Jan 10 '20 11:01

karnataka


2 Answers

Keycloak < 17.0.0:

the default database is located in /opt/jboss/keycloak/standalone/data/ the name is keycloak.mv.db

if you want to back it up, I suggest mapping a volume when running keycloak:

docker run --volume /root/keycloak/data/:/opt/jboss/keycloak/standalone/data/ ...

this way the database will stay on the host and will keep the changes even if you destroy the container and recreate it.

For Keycloak >= 17.0.0:

the default database is located in /opt/keycloak/data/h2/ the name is keycloakdb.mv.db

if you want to back it up, map the following volume when running keycloak:

docker run --volume /root/keycloak/data/:/opt/keycloak/data/h2/ ...

The whole data folder could also be used (instead of h2).

like image 68
rptmat57 Avatar answered Oct 13 '22 13:10

rptmat57


By default, Keycloak is using its embedded H2 database. I suggest that you move to an external DB so that you will be able to managed backup more simply.

see https://www.keycloak.org/docs/latest/server_installation/index.html#_database and https://github.com/keycloak/keycloak-containers/tree/master/server#database regarding the supported DB and how to setup env variables to connect to the DB from the Keycloak container.

Regards,

like image 45
Fabrice G. Avatar answered Oct 13 '22 12:10

Fabrice G.