title: How to use docker volume to deploy war / jar in Tomcat
body: <p>Is it possible to deploy some java war or jar file in Tomcat? I looking for a lot of tutorials and the only solution I found is copy project war file into <code>/usr/local/tomcat/webapps/</code>.</p>
  
  <p>I actually used that solution but I would like to improve my dockerisation. My primary goal is when I run my 2 images (application in tomcat and db image) with docker-compose I want to use my local war file of target folder in tomcat, and, when I build war again after the code changed, that change will be reflected without stopping containers, removing, and rebuilding. Can you help to do that? My attempts failed. I want it just for development purpose.</p>
  
  <p>Here is my docker-compose.yml</p>
  
  <pre><code>version: '3'
  
  services:
  
    tomcat-service:
      build:
        context: ../
        dockerfile: docker/app/Dockerfile
      volumes:
        - D:\myproj\target\app.war:/usr/local/tomcat/webapps/ROOT.war
      ports:
        - "8080:8080"
      depends_on:
        - "db-service"
  
    db-service:
      build: ./database
      ports:
        - "5433:5432"
  </code></pre>
  
  <p>and Dockerfile for that tomcat</p>
  
  <pre><code>FROM tomcat:8.0-jre8
  RUN rm -rvf /usr/local/tomcat/webapps/ROOT
  COPY ./docker/app/context.xml /usr/local/tomcat/conf/
  # with following copy command it works, but when I rebuild war file, I need stop docker-compose and build and run it again .. I want use volume instead of copy war
  #COPY ./pnp-web/target/pnp.war /usr/local/tomcat/webapps/ROOT.war
  EXPOSE 8080
  CMD ["catalina.sh", "run"]
  </code></pre>
  
  <p>With configuration above applicaton starts, but when I run <code>mvn clean package</code> application is not loaded anymore</p>
  
  <p>EDIT</p>
  
  <p>I checked log of tomcat container and I found this error:</p>
  
  <pre><code>tomcat-cont       | 10-Jul-2018 08:20:36.754 INFO [localhost-startStop-1] org.apache.catalina.startup.HostConfig.deployWAR Deploying web application archive /usr/local/tomcat/webapps/ROOT.war
  tomcat-cont       | 10-Jul-2018 08:20:36.858 SEVERE [localhost-startStop-1] org.apache.catalina.core.ContainerBase.addChildInternal ContainerBase.addChild: start:
  tomcat-cont       |  org.apache.catalina.LifecycleException: Failed to start component [StandardEngine[Catalina].StandardHost[localhost].StandardContext[]]
  tomcat-cont       |     at org.apache.catalina.util.LifecycleBase.start(LifecycleBase.java:162)
  tomcat-cont       |     at org.apache.catalina.core.ContainerBase.addChildInternal(ContainerBase.java:755)
  tomcat-cont       |     at org.apache.catalina.core.ContainerBase.addChild(ContainerBase.java:731)
  tomcat-cont       |     at org.apache.catalina.core.StandardHost.addChild(StandardHost.java:717)
  tomcat-cont       |     at org.apache.catalina.startup.HostConfig.deployWAR(HostConfig.java:973)
  tomcat-cont       |     at org.apache.catalina.startup.HostConfig$DeployWar.run(HostConfig.java:1850)
  tomcat-cont       |     at java.util.concurrent.Executors$RunnableAdapter.call(Executors.java:511)
  tomcat-cont       |     at java.util.concurrent.FutureTask.run(FutureTask.java:266)
  tomcat-cont       |     at java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1149)
  tomcat-cont       |     at java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:624)
  tomcat-cont       |     at java.lang.Thread.run(Thread.java:748)
  tomcat-cont       | Caused by: org.apache.catalina.LifecycleException: Failed to start component [org.apache.catalina.webresources.StandardRoot@51f50cb1]
  tomcat-cont       |     at org.apache.catalina.util.LifecycleBase.start(LifecycleBase.java:162)
  tomcat-cont       |     at org.apache.catalina.core.StandardContext.resourcesStart(StandardContext.java:5016)
  tomcat-cont       |     at org.apache.catalina.core.StandardContext.startInternal(StandardContext.java:5149)
  tomcat-cont       |     at org.apache.catalina.util.LifecycleBase.start(LifecycleBase.java:145)
  tomcat-cont       |     ... 10 more
  tomcat-cont       | Caused by: org.apache.catalina.LifecycleException: Failed to initialize component [org.apache.catalina.webresources.JarResourceSet@20e48a4a]
  tomcat-cont       |     at org.apache.catalina.util.LifecycleBase.init(LifecycleBase.java:107)
  tomcat-cont       |     at org.apache.catalina.util.LifecycleBase.start(LifecycleBase.java:135)
  tomcat-cont       |     at org.apache.catalina.webresources.StandardRoot.startInternal(StandardRoot.java:722)
  tomcat-cont       |     at org.apache.catalina.util.LifecycleBase.start(LifecycleBase.java:145)
  tomcat-cont       |     ... 13 more
  tomcat-cont       | Caused by: java.lang.IllegalArgumentException: java.util.zip.ZipException: error in opening zip file
  tomcat-cont       |     at org.apache.catalina.webresources.AbstractSingleArchiveResourceSet.initInternal(AbstractSingleArchiveResourceSet.java:142)
  tomcat-cont       |     at org.apache.catalina.util.LifecycleBase.init(LifecycleBase.java:102)
  tomcat-cont       |     ... 16 more
  tomcat-cont       | Caused by: java.util.zip.ZipException: error in opening zip file
  tomcat-cont       |     at java.util.zip.ZipFile.open(Native Method)
  tomcat-cont       |     at java.util.zip.ZipFile.&lt;init&gt;(ZipFile.java:225)
  tomcat-cont       |     at java.util.zip.ZipFile.&lt;init&gt;(ZipFile.java:155)
  tomcat-cont       |     at java.util.jar.JarFile.&lt;init&gt;(JarFile.java:166)
  tomcat-cont       |     at java.util.jar.JarFile.&lt;init&gt;(JarFile.java:130)
  tomcat-cont       |     at org.apache.tomcat.util.compat.JreCompat.jarFileNewInstance(JreCompat.java:170)
  tomcat-cont       |     at org.apache.tomcat.util.compat.JreCompat.jarFileNewInstance(JreCompat.java:155)
  tomcat-cont       |     at org.apache.catalina.webresources.AbstractSingleArchiveResourceSet.initInternal(AbstractSingleArchiveResourceSet.java:139)
  tomcat-cont       |     ... 17 more
  tomcat-cont       |
  tomcat-cont       | 10-Jul-2018 08:20:36.859 SEVERE [localhost-startStop-1] org.apache.catalina.startup.HostConfig.deployWAR Error deploying web application archive /usr/local/tomcat/webapps/ROOT.war
  tomcat-cont       |  java.lang.IllegalStateException: ContainerBase.addChild: start: org.apache.catalina.LifecycleException: Failed to start component [StandardEngine[Catalina].StandardHost[localhost].Stand
  ardContext[]]
  tomcat-cont       |     at org.apache.catalina.core.ContainerBase.addChildInternal(ContainerBase.java:759)
  tomcat-cont       |     at org.apache.catalina.core.ContainerBase.addChild(ContainerBase.java:731)
  tomcat-cont       |     at org.apache.catalina.core.StandardHost.addChild(StandardHost.java:717)
  tomcat-cont       |     at org.apache.catalina.startup.HostConfig.deployWAR(HostConfig.java:973)
  tomcat-cont       |     at org.apache.catalina.startup.HostConfig$DeployWar.run(HostConfig.java:1850)
  tomcat-cont       |     at java.util.concurrent.Executors$RunnableAdapter.call(Executors.java:511)
  tomcat-cont       |     at java.util.concurrent.FutureTask.run(FutureTask.java:266)
  tomcat-cont       |     at java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1149)
  tomcat-cont       |     at java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:624)
  tomcat-cont       |     at java.lang.Thread.run(Thread.java:748)
  tomcat-cont       |
  tomcat-cont       | 10-Jul-2018 08:20:36.860 INFO [localhost-startStop-1] org.apache.catalina.startup.HostConfig.deployWAR Deployment of web application archive /usr/local/tomcat/webapps/ROOT.war has finish
  ed in 105 ms
  </code></pre>
  
  <p>this error happened when I wanted to try restart container when new war is builded.</p>