title: Deploying app on Docker with Tomcat and PostgreSQL
body: <p>I have an testApp.war which I'd like to <strong>deploy on Tomcat through docker</strong> (docker is on 10.0.2.157). My testApp will work properly only with <strong>postgres DB</strong> and specified user testUser and password testUserPasswd. I built such a structure: </p>
  
  <pre><code>.
  ├── db
  │   ├── Dockerfile
  │   ├── pg_hba.conf
  │   └── postgresql.conf
  ├── docker-compose.yml
  └── web
      ├── context.xml
      ├── Dockerfile
      ├── software
      │   └── testApp.war
      └── tomcat-users.xml
  </code></pre>
  
  <p>Content of all these files are attached below. I start my containers with command:</p>
  
  <pre><code>docker-compose up -d
  </code></pre>
  
  <p>However when I go to Tomcat on webbrowser (<a href="http://10.0.2.157:8282/manager/html" rel="nofollow noreferrer">http://10.0.2.157:8282/manager/html</a>) and try to start my testApp I got:</p>
  
  <blockquote>
    <p>HTTP Status 404 – Not Found </p>
    
    <p>Type Status Report </p>
    
    <p>Message /testApp/</p>
    
    <p>Description The origin server did not find a current representation
    for the target resource or is not willing to disclose that one exists.</p>
    
    <p>Apache Tomcat/8.5.20</p>
  </blockquote>
  
  <p><strong>What I'm doing wrong? Could you help me with this?</strong></p>
  
  <hr>
  
  <p>db/Dockerfile</p>
  
  <pre><code>FROM postgres:9.5
  MAINTAINER riwaniak
  
  ENV POSTGRES_USER testUser
  ENV POSTGRES_PASSWORD testUserPasswd
  ENV POSTGRES_DB testUser
  
  ADD pg_hba.conf /etc/postgresql/9.5/main/
  ADD postgresql.conf /etc/postgresql/9.5/main/
  </code></pre>
  
  <p>db/pg_hba.conf</p>
  
  <pre><code>local   all             all                                     trust
  host    all             all             127.0.0.1/32            md5
  host    all             all             0.0.0.0/0               md5
  host    all
  </code></pre>
  
  <p>db/postgresql.conf</p>
  
  <pre><code>listen_addresses='*'
  </code></pre>
  
  <p>web/context.xml</p>
  
  <pre><code>&lt;?xml version="1.0" encoding="UTF-8"?&gt;
  
  &lt;Context antiResourceLocking="false" privileged="true" &gt;
  &lt;!--
      &lt;Valve className="org.apache.catalina.valves.RemoteAddrValve"
           allow="127\.\d+\.\d+\.\d+|::1|0:0:0:0:0:0:0:1" /&gt;
  --&gt;
  &lt;/Context&gt;
  </code></pre>
  
  <p>web/Dockerfile</p>
  
  <pre><code>FROM tomcat:8.5.20-jre8
  MAINTAINER riwaniak
  
  COPY ./software /usr/local/tomcat/webapps/
  
  CMD ["catalina.sh", "run"]
  </code></pre>
  
  <p>web/tomcat-users.xml</p>
  
  <pre><code>&lt;?xml version="1.0" encoding="UTF-8"?&gt;
  &lt;tomcat-users xmlns="http://tomcat.apache.org/xml"
                xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
                xsi:schemaLocation="http://tomcat.apache.org/xml tomcat-users.xsd"
                version="1.0"&gt;
  
    &lt;role rolename="tomcat"/&gt;
    &lt;role rolename="admin-gui"/&gt;
    &lt;role rolename="manager-gui"/&gt;
  
    &lt;user username="tomcat" password="tomcat" roles="tomcat,admin-gui,manager-gui"/&gt;
  
  &lt;/tomcat-users&gt;
  </code></pre>
  
  <p>and finally docker-compose.yml</p>
  
  <pre><code>version: '2'
  services:
      testApp:
          build: ./web
          volumes:
            - /path/to/tomcat/folder/web/tomcat-users.xml:/usr/local/tomcat/conf/tomcat-users.xml
            - /path/to/tomcat/folder/web/context.xml:/usr/local/tomcat/webapps/HelpdeskApp/META-INF/context.xml
            - /path/to/tomcat/folder/web/context.xml:/usr/local/tomcat/webapps/host-manager/META-INF/context.xml
            - /path/to/tomcat/folder/web/context.xml:/usr/local/tomcat/webapps/manager/META-INF/context.xml
          ports:
            - "8282:8080"
          links:
            - testAppdb
          networks:
            - testAppnet
  
      testAppdb:
          build: ./db
          ports:
            - "5555:5432"
          volumes:
            - /srv/docker/postgresql:/var/lib/postgresql
            - /path/to/tomcat/folder/db/postgresql.conf:/etc/postgresql/9.5/main/postgresql.conf
            - /path/to/tomcat/folder/db/pg_hba.conf:/etc/postgresql/9.5/main/pg_hba.conf
          command: postgres -c config_file=/etc/postgresql/9.5/main/postgresql.conf
          networks:
            - testAppnet
  
  networks:
      testAppnet:
        driver: bridge
        ipam:
          driver: default
          config:
            - subnet: 172.28.0.0/16
  </code></pre>