I am using a script to backup and restore our Keycloak configuration. The restore.sh script should copy the realms config inside the container and use it run the import command:

docker cp -q $BACKUP_LOCATION $CONTAINER_NAME:/tmp/kc_backup
docker exec $CONTAINER_NAME sh /opt/keycloak/bin/kc.sh import --dir /tmp/kc_backup --override true
docker exec $CONTAINER_NAME rm -rf /tmp/kc_backup

The problem is that docker cp copies the files with uid:gid of the host machine, so then the rm -rf operation fails.

Keycloak is running on a container created with the official Docker image, that is based on RedHat ubi9 minimal (or micro?). This image does not have sudo, so I cannot run sudo chown to change the permissions.

I thought docker cp should change the ownership automatically during copying to avoid these problems, but seems like it is not working like this. What options to I have to fix this then?

0

There are 0 best solutions below