title: Docker-compose, deploy war to Tomcat, run oracle service
body: <p>Given I have following scenario:</p>
  
  <p>I want to deploy web application to Tomcat, which connects to the oracle database and display data to the user</p>
  
  <p>What I will need is the following:</p>
  
  <ul>
  <li><p>Docker compose yml</p></li>
  <li><p>Tomcat docker image - war is deployed here</p></li>
  <li><p>Oracle docker image</p></li>
  <li><p>fatdb jar deployment - I have liquibase scripts which update db schema packaged up as fatdb jar</p></li>
  </ul>
  
  <p>The solution could be:</p>
  
  <pre><code>version: '2'
  services:
    web-tomcat:
      image: tomcat:jre8
      depends_on:
        - db-oracle
    db-oracle:
      image: wnameless/oracle-xe-11g
  </code></pre>
  
  <p>BUT, multiple problems gotta be solved:</p>
  
  <ol>
  <li>waiting for oracle service to be ready - solved with waiting wrapper as advised in docker docs: <a href="https://github.com/vishnubob/wait-for-it" rel="nofollow noreferrer">wait-for-it</a></li>
  <li>waiting for users to be created - solved by waiting loop which tries to connect to oracle db with user being created</li>
  <li>waiting for the db schema being prepared by liquibase fatdb deployment and after that deploying war to tomcat</li>
  <li>not ending up in the situation I spin up separate container to do the fatdb deployment and after that it would just stay in Exited (0) state as fatdb deployment is one-off thing, not a service</li>
  </ol>
  
  <p>I ended up creating entrypoint.sh script in order to have db ready before war deployment:</p>
  
  <pre><code>java -jar fatdb.jar update
  catalina.sh run
  </code></pre>
  
  <p>and overriding entrypoint in tomcat image</p>
  
  <p><strong>Is there better solution how to prepare database schema before war deployment in docker-compose?</strong></p>