title: Keycloak Docker container fails to start after restarting the container
body: <p>I have a Keycloak installation running as docker container in a docker-compose environment. Every night, my backup stops relevant containers, performs a DB and volume backup and restarts the containers again. For most it works, but Keycloak seems to have a problem with it and does not come up again afterwards. Looking at the logs, the error message is:</p>
  
  <pre><code>The batch failed with the following error: : 
  keycloak           | WFLYCTL0062: Composite operation failed and was rolled back. Steps that failed:
  keycloak           | Step: step-9
  keycloak           | Operation: /subsystem=datasources/jdbc-driver=postgresql:add(driver-name=postgresql, driver-module-name=org.postgresql.jdbc, driver-xa-datasource-class-name=org.postgresql.xa.PGXADataSource)
  keycloak           | Failure: WFLYCTL0212: Duplicate resource [
  keycloak           |     ("subsystem" =&gt; "datasources"),
  keycloak           |     ("jdbc-driver" =&gt; "postgresql")
  keycloak           | ]
  ...
  The batch failed with the following error: : 
  keycloak           | WFLYCTL0062: Composite operation failed and was rolled back. Steps that failed:
  keycloak           | Step: step-9
  keycloak           | Operation: /subsystem=datasources/jdbc-driver=postgresql:add(driver-name=postgresql, driver-module-name=org.postgresql.jdbc, driver-xa-datasource-class-name=org.postgresql.xa.PGXADataSource)
  keycloak           | Failure: WFLYCTL0212: Duplicate resource [
  keycloak           |     ("subsystem" =&gt; "datasources"),
  keycloak           |     ("jdbc-driver" =&gt; "postgresql")
  keycloak           | ]
  </code></pre>
  
  <p>The <code>docker-compose.yml</code> entry for Keycloak looks as follows, important data obviously removed</p>
  
  <pre><code>  keycloak:
      image: jboss/keycloak:8.0.1
      container_name: keycloak
      environment:
        - PROXY_ADDRESS_FORWARDING=true
        - DB_VENDOR=postgres
        - DB_ADDR=db
        - DB_DATABASE=keycloak
        - DB_USER=keycloak
        - DB_PASSWORD=&lt;password&gt;
        - VIRTUAL_HOST=&lt;url&gt;
        - VIRTUAL_PORT=8080
        - LETSENCRYPT_HOST=&lt;url&gt;
      volumes:
        - /opt/docker/keycloak-startup:/opt/jboss/startup-scripts
  </code></pre>
  
  <p>The volume I'm mapping is there to make some changes to WildFly to make sure it behaves well with the reverse proxy:</p>
  
  <pre><code>embed-server --std-out=echo
  
  #  Enable https listener for the new security realm
  /subsystem=undertow/ \
    server=default-server/ \
      http-listener=default \
        :write-attribute(name=proxy-address-forwarding, \
                         value=true)
  
  #  Create new socket binding with proxy https port
  /socket-binding-group=standard-sockets/ \
    socket-binding=proxy-https \
      :add(port=443)
  
  #  Enable https listener for the new security realm
  /subsystem=undertow/ \
    server=default-server/ \
      http-listener=default \
        :write-attribute(name=redirect-socket, \
                         value="proxy-https")
  </code></pre>
  
  <p>After stopping the container, its not starting anymore with the messages shown above. Removing the container and re-creating it works fine however. I tried to remove the volume after the initial start, this doesn't really make a difference either. I already learned that I have to remove the <code>KEYCLOAK_USER=admin</code> and <code>KEYCLOAK_PASSWORD</code> environment variables after the initial boot as otherwise the container complains that the user already exists and doesn't start anymore. Any idea how to fix that?</p>