title: SpringBoot WAR 404 in Tomcat Container
body: <p>I'm trying to dockerize my Spring Boot Application.</p>
  <p>Here my docker-compose file</p>
  <pre><code>version: '3.8'
  
  
  services:
      
      mysql:
          image: mysql:latest
          ports:
              - 3306:3306
          hostname: mysql
          environment:
              MYSQL_DATABASE: ######
              MYSQL_ROOT_PASSWORD: ######
              MYSQL_USER: ######
              MYSQL_PASSWORD: ######
          volumes:
              - ./mysqldata:/var/lib/mysql
      
      backend:
          
          build: 
              context: .
              dockerfile: dockerfile
          ports:
              - 8080:8080
          depends_on:
              - mysql
                  
  </code></pre>
  <p>My dockerfile</p>
  <pre><code>FROM maven:3.8.4-eclipse-temurin-17-alpine AS maven
  
  RUN mkdir -p /build
  
  COPY pom.xml /build
  
  COPY src /build/src
  
  WORKDIR /build
  
  RUN mvn -B dependency:resolve dependency:resolve-plugins
  
  RUN mvn -DskipTests clean package
  
  FROM tomcat:jdk8-corretto
  
  EXPOSE 8080
  
  RUN rm -rf /usr/local/tomcat/webapps/ROOT
  
  COPY --from=maven /build/target/promogen.war /usr/local/tomcat/webapps/ROOT.war
  
  CMD [&quot;catalina.sh&quot;,&quot;run&quot;]
  </code></pre>
  <p>Inspecting backend I can see that my war is deployed. In logs I can see</p>
  <pre><code>2021 15:10:57.180 INFO [main] org.apache.catalina.startup.HostConfig.deployWAR Deploying web application archive [/usr/local/tomcat/webapps/ROOT.war]
  
  </code></pre>
  <p>Inside /usr/local/tomcat/webapps dir I can see that ROOT.war and ROOT folder exists.
  I'm starting docker with the following command:</p>
  <pre><code>docker-compose up --build
  
  </code></pre>
  <p>When I access localhost:8080 Tomcat says Http Status 404 - Not Found.</p>
  <p>Here logs after executing docker-compose up:</p>
  <pre><code>➜  PromogenServer git:(master) ✗ docker-compose up --build
  Building backend
  [+] Building 3.3s (16/16) FINISHED
   =&gt; [internal] load build definition from dockerfile                                                                                                       0.4s
   =&gt; =&gt; transferring dockerfile: 37B                                                                                                                        0.0s
   =&gt; [internal] load .dockerignore                                                                                                                          0.4s
   =&gt; =&gt; transferring context: 2B                                                                                                                            0.0s
   =&gt; [internal] load metadata for docker.io/library/tomcat:jdk8-corretto                                                                                    1.8s
   =&gt; [internal] load metadata for docker.io/library/maven:3.8.4-eclipse-temurin-17-alpine                                                                   1.7s
   =&gt; [stage-1 1/3] FROM docker.io/library/tomcat:jdk8-corretto@sha256:e78680bd172c7388fb9ed123423f671c2815560412ad2df8cc73f79b7922890e                      0.0s
   =&gt; [internal] load build context                                                                                                                          0.3s
   =&gt; =&gt; transferring context: 37.39kB                                                                                                                       0.0s
   =&gt; [maven 1/7] FROM docker.io/library/maven:3.8.4-eclipse-temurin-17-alpine@sha256:d7d5ef47f898d0ef33fb472dc63fcc67face715e337efd1728107fc9e195388d       0.0s
   =&gt; CACHED [stage-1 2/3] RUN rm -rf /usr/local/tomcat/webapps/ROOT                                                                                         0.0s
   =&gt; CACHED [maven 2/7] RUN mkdir -p /build                                                                                                                 0.0s
   =&gt; CACHED [maven 3/7] COPY pom.xml /build                                                                                                                 0.0s
   =&gt; CACHED [maven 4/7] COPY src /build/src                                                                                                                 0.0s
   =&gt; CACHED [maven 5/7] WORKDIR /build                                                                                                                      0.0s
   =&gt; CACHED [maven 6/7] RUN mvn -B dependency:resolve dependency:resolve-plugins                                                                            0.0s
   =&gt; CACHED [maven 7/7] RUN mvn -DskipTests clean package                                                                                                   0.0s
   =&gt; CACHED [stage-1 3/3] COPY --from=maven /build/target/promogen.war /usr/local/tomcat/webapps/ROOT.war                                                   0.0s
   =&gt; exporting to image                                                                                                                                     0.3s
   =&gt; =&gt; exporting layers                                                                                                                                    0.0s
   =&gt; =&gt; writing image sha256:6a591e6448a22aefbd44a2c5b62940acdb46b581005de8e5fe940113c6de7acf                                                               0.1s
   =&gt; =&gt; naming to docker.io/library/promogenserver_backend                                                                                                  0.0s
  
  Use 'docker scan' to run Snyk tests against images to find vulnerabilities and learn how to fix them
  Starting promogenserver_mysql_1 ... done
  Starting promogenserver_backend_1 ... done
  Attaching to promogenserver_mysql_1, promogenserver_backend_1
  mysql_1    | 2021-12-20 15:19:38+00:00 [Note] [Entrypoint]: Entrypoint script for MySQL Server 8.0.27-1debian10 started.
  mysql_1    | 2021-12-20 15:19:39+00:00 [Note] [Entrypoint]: Switching to dedicated user 'mysql'
  mysql_1    | 2021-12-20 15:19:39+00:00 [Note] [Entrypoint]: Entrypoint script for MySQL Server 8.0.27-1debian10 started.
  mysql_1    | 2021-12-20T15:19:40.133565Z 0 [System] [MY-010116] [Server] /usr/sbin/mysqld (mysqld 8.0.27) starting as process 1
  mysql_1    | 2021-12-20T15:19:40.158480Z 0 [Warning] [MY-010159] [Server] Setting lower_case_table_names=2 because file system for /var/lib/mysql/ is case insensitive
  mysql_1    | 2021-12-20T15:19:40.214360Z 1 [System] [MY-013576] [InnoDB] InnoDB initialization has started.
  backend_1  | 20-Dec-2021 15:19:42.185 INFO [main] org.apache.catalina.startup.VersionLoggerListener.log Server version name:   Apache Tomcat/10.0.14
  backend_1  | 20-Dec-2021 15:19:42.192 INFO [main] org.apache.catalina.startup.VersionLoggerListener.log Server built:          Dec 2 2021 22:01:36 UTC
  backend_1  | 20-Dec-2021 15:19:42.193 INFO [main] org.apache.catalina.startup.VersionLoggerListener.log Server version number: 10.0.14.0
  backend_1  | 20-Dec-2021 15:19:42.193 INFO [main] org.apache.catalina.startup.VersionLoggerListener.log OS Name:               Linux
  backend_1  | 20-Dec-2021 15:19:42.193 INFO [main] org.apache.catalina.startup.VersionLoggerListener.log OS Version:            5.10.47-linuxkit
  backend_1  | 20-Dec-2021 15:19:42.194 INFO [main] org.apache.catalina.startup.VersionLoggerListener.log Architecture:          amd64
  backend_1  | 20-Dec-2021 15:19:42.194 INFO [main] org.apache.catalina.startup.VersionLoggerListener.log Java Home:             /usr/lib/jvm/java-1.8.0-amazon-corretto/jre
  backend_1  | 20-Dec-2021 15:19:42.195 INFO [main] org.apache.catalina.startup.VersionLoggerListener.log JVM Version:           1.8.0_312-b07
  backend_1  | 20-Dec-2021 15:19:42.195 INFO [main] org.apache.catalina.startup.VersionLoggerListener.log JVM Vendor:            Amazon.com Inc.
  backend_1  | 20-Dec-2021 15:19:42.196 INFO [main] org.apache.catalina.startup.VersionLoggerListener.log CATALINA_BASE:         /usr/local/tomcat
  backend_1  | 20-Dec-2021 15:19:42.196 INFO [main] org.apache.catalina.startup.VersionLoggerListener.log CATALINA_HOME:         /usr/local/tomcat
  backend_1  | 20-Dec-2021 15:19:42.209 INFO [main] org.apache.catalina.startup.VersionLoggerListener.log Command line argument: -Djava.util.logging.config.file=/usr/local/tomcat/conf/logging.properties
  backend_1  | 20-Dec-2021 15:19:42.210 INFO [main] org.apache.catalina.startup.VersionLoggerListener.log Command line argument: -Djava.util.logging.manager=org.apache.juli.ClassLoaderLogManager
  backend_1  | 20-Dec-2021 15:19:42.211 INFO [main] org.apache.catalina.startup.VersionLoggerListener.log Command line argument: -Djdk.tls.ephemeralDHKeySize=2048
  backend_1  | 20-Dec-2021 15:19:42.211 INFO [main] org.apache.catalina.startup.VersionLoggerListener.log Command line argument: -Djava.protocol.handler.pkgs=org.apache.catalina.webresources
  backend_1  | 20-Dec-2021 15:19:42.212 INFO [main] org.apache.catalina.startup.VersionLoggerListener.log Command line argument: -Dorg.apache.catalina.security.SecurityListener.UMASK=0027
  backend_1  | 20-Dec-2021 15:19:42.212 INFO [main] org.apache.catalina.startup.VersionLoggerListener.log Command line argument: -Dignore.endorsed.dirs=
  backend_1  | 20-Dec-2021 15:19:42.213 INFO [main] org.apache.catalina.startup.VersionLoggerListener.log Command line argument: -Dcatalina.base=/usr/local/tomcat
  backend_1  | 20-Dec-2021 15:19:42.213 INFO [main] org.apache.catalina.startup.VersionLoggerListener.log Command line argument: -Dcatalina.home=/usr/local/tomcat
  backend_1  | 20-Dec-2021 15:19:42.213 INFO [main] org.apache.catalina.startup.VersionLoggerListener.log Command line argument: -Djava.io.tmpdir=/usr/local/tomcat/temp
  backend_1  | 20-Dec-2021 15:19:42.234 INFO [main] org.apache.catalina.core.AprLifecycleListener.lifecycleEvent Loaded Apache Tomcat Native library [1.2.31] using APR version [1.7.0].
  backend_1  | 20-Dec-2021 15:19:42.234 INFO [main] org.apache.catalina.core.AprLifecycleListener.lifecycleEvent APR capabilities: IPv6 [true], sendfile [true], accept filters [false], random [true], UDS [true].
  backend_1  | 20-Dec-2021 15:19:42.248 INFO [main] org.apache.catalina.core.AprLifecycleListener.initializeSSL OpenSSL successfully initialized [OpenSSL 1.1.1g FIPS  21 Apr 2020]
  backend_1  | 20-Dec-2021 15:19:43.623 INFO [main] org.apache.coyote.AbstractProtocol.init Initializing ProtocolHandler [&quot;http-nio-8080&quot;]
  backend_1  | 20-Dec-2021 15:19:43.690 INFO [main] org.apache.catalina.startup.Catalina.load Server initialization in [2225] milliseconds
  backend_1  | 20-Dec-2021 15:19:43.791 INFO [main] org.apache.catalina.core.StandardService.startInternal Starting service [Catalina]
  backend_1  | 20-Dec-2021 15:19:43.791 INFO [main] org.apache.catalina.core.StandardEngine.startInternal Starting Servlet engine: [Apache Tomcat/10.0.14]
  backend_1  | 20-Dec-2021 15:19:43.873 INFO [main] org.apache.catalina.startup.HostConfig.deployWAR Deploying web application archive [/usr/local/tomcat/webapps/ROOT.war]
  mysql_1    | 2021-12-20T15:19:45.785479Z 1 [System] [MY-013577] [InnoDB] InnoDB initialization has ended.
  mysql_1    | 2021-12-20T15:19:47.572660Z 0 [System] [MY-010229] [Server] Starting XA crash recovery...
  mysql_1    | 2021-12-20T15:19:47.610076Z 0 [System] [MY-010232] [Server] XA crash recovery finished.
  mysql_1    | 2021-12-20T15:19:48.760762Z 0 [Warning] [MY-013746] [Server] A deprecated TLS version TLSv1 is enabled for channel mysql_main
  mysql_1    | 2021-12-20T15:19:48.760872Z 0 [Warning] [MY-013746] [Server] A deprecated TLS version TLSv1.1 is enabled for channel mysql_main
  mysql_1    | 2021-12-20T15:19:48.778784Z 0 [Warning] [MY-010068] [Server] CA certificate ca.pem is self signed.
  mysql_1    | 2021-12-20T15:19:48.779013Z 0 [System] [MY-013602] [Server] Channel mysql_main configured to support TLS. Encrypted connections are now supported for this channel.
  mysql_1    | 2021-12-20T15:19:48.843650Z 0 [Warning] [MY-011810] [Server] Insecure configuration for --pid-file: Location '/var/run/mysqld' in the path is accessible to all OS users. Consider choosing a different directory.
  mysql_1    | 2021-12-20T15:19:49.192746Z 0 [System] [MY-011323] [Server] X Plugin ready for connections. Bind-address: '::' port: 33060, socket: /var/run/mysqld/mysqlx.sock
  mysql_1    | 2021-12-20T15:19:49.193439Z 0 [System] [MY-010931] [Server] /usr/sbin/mysqld: ready for connections. Version: '8.0.27'  socket: '/var/run/mysqld/mysqld.sock'  port: 3306  MySQL Community Server - GPL.
  backend_1  | 20-Dec-2021 15:19:51.902 INFO [main] org.apache.jasper.servlet.TldScanner.scanJars At least one JAR was scanned for TLDs yet contained no TLDs. Enable debug logging for this logger for a complete list of JARs that were scanned but no TLDs were found in them. Skipping unneeded JARs during scanning can improve startup time and JSP compilation time.
  backend_1  | 20-Dec-2021 15:19:52.042 INFO [main] org.apache.catalina.startup.HostConfig.deployWAR Deployment of web application archive [/usr/local/tomcat/webapps/ROOT.war] has finished in [8,166] ms
  backend_1  | 20-Dec-2021 15:19:52.054 INFO [main] org.apache.coyote.AbstractProtocol.start Starting ProtocolHandler [&quot;http-nio-8080&quot;]
  backend_1  | 20-Dec-2021 15:19:52.081 INFO [main] org.apache.catalina.startup.Catalina.start Server startup in [8390] milliseconds
  </code></pre>
  <p>EDIT 1:</p>
  <p>I changed tomcat image to</p>
  <pre><code>tomcat:8.5-jdk17-corretto
  </code></pre>
  <p>And now Spring application starts but complains about mysql connection:</p>
  <pre><code> Caused by: java.net.ConnectException: Connection refused
  
  </code></pre>
  <p>EDIT 2:</p>
  <p>I solved it. I changed my application.properties from</p>
  <pre><code>spring.datasource.url=jdbc:mysql://127.0.0.1:3306/promogen
  
  </code></pre>
  <p>to</p>
  <pre><code>spring.datasource.url=jdbc:mysql://mysql:3306/promogen
  
  </code></pre>
  <p>Where mysql is the String I used in services in docker-compose.yml file</p>