Keycloak Docker container fails to start after restarting the container Keycloak Docker container fails to start after restarting the container docker docker

Keycloak Docker container fails to start after restarting the container


Update on 23rd of May 2021:

The issue has been resolved on RedHats Jira, it seems to be resolved in version 12. The related GitHub pull request can be found here: https://github.com/keycloak/keycloak-containers/pull/286


According to RedHat support, this is a known "issue" and not supposed to be fixed. They want to concentrate on a workflow where a container is removed and recreated, not started and stopped. They agreed with the general problem, but stated that currently there are no resources available. Stopping and starting the container is a operation which is currently not supported.

See for example https://issues.redhat.com/browse/KEYCLOAK-13094?jql=project%20%3D%20KEYCLOAK%20AND%20text%20~%20%22docker%20restart%22 for reference


A legitimate use case for restarting is to add debug logging. For example to debug authentication with an external identity provider.

I ended up creating a shell script that does:

  • docker stop [container]
  • docker rm [container]
  • recreates the image i want with changes to the logging configuration
  • docker run [options] [container]

However a nice feature of docker is the ability to restart a stopped container automatically, decreasing downtime. This Keycloak bug takes that feature away.


I had the same problem here, and my solution was:

  1. Export docker container to a .tar file:

docker export CONTAINER_NAME > latest.tar

2- Create a new volume in a docker

docker volume create VOLUME_NAME

3 - Start a new docker container mapping the volume created to a container db path, something like this:

docker run --name keycloak2 -v keycloak_db:/opt/jboss/keycloak/standalone/data/ -p 8080:8080 -e PROXY_ADDRESS_FORWARDING=true -e KEYCLOAK_USER=admin -e KEYCLOAK_PASSWORD=root jboss/keycloak

4 - Stop the container

5 - Unpack the tar file and find the database path, something like this:

tar unpack path: /opt/jboss/keycloak/standalone/data

6 - Move the path content to docker volume, if you dont know where is the physical path use docker inspect volume VOLUME_NAME to find the path

7 - Start the stoped container

This works for me, I hope its so helpfull to the next person to fix this problem.