Standalone docker keycloak fails to reconnect to the database


I have a working keycloak cluster with docker instances on separate nodes clustered with JDBC_PING.
When starting the instances with external postgresql reachable, everything is fine. Stop the db and restart it later works well. Keycloak automatically reconnects.

The problem I have is when starting keycloak without connectivity to the db. In this case the container restarts every N seconds, which is fine (restart=unless-stopped).
When the db becomes available, keycloak does not detect it on the next start. It just keeps restarting
The only way to make it work is to do a docker-compose down && docker-compose up -d

Any suggestion on how to make it work properly?