I'm trying to deploy a war file in a Tomcat Docker container, but always get 404 Not Found
page. I created the Spring Boot project by following Intellij Tutorial, and it works fine on my machine locally.
Here is my Dockerfile:
FROM tomcat:latest
ADD WebTutorial.war /usr/local/tomcat/webapps/ROOT.war
I use the following command to build the image and run container:
$ docker build -t sp-tomcat .
$ docker run -it -p 8080:8080 --name sp-tomcat sp-tomcat
After the container is running, I logged into the container and see the war file has been deployed (I suppose):
Here is the log output:
21-Dec-2021 07:41:35.819 INFO [main] org.apache.catalina.startup.VersionLoggerListener.log Server version name: Apache Tomcat/10.0.14
21-Dec-2021 07:41:35.821 INFO [main] org.apache.catalina.startup.VersionLoggerListener.log Server built: Dec 2 2021 22:01:36 UTC
21-Dec-2021 07:41:35.821 INFO [main] org.apache.catalina.startup.VersionLoggerListener.log Server version number: 10.0.14.0
21-Dec-2021 07:41:35.821 INFO [main] org.apache.catalina.startup.VersionLoggerListener.log OS Name: Linux
21-Dec-2021 07:41:35.822 INFO [main] org.apache.catalina.startup.VersionLoggerListener.log OS Version: 5.10.76-linuxkit
21-Dec-2021 07:41:35.822 INFO [main] org.apache.catalina.startup.VersionLoggerListener.log Architecture: aarch64
21-Dec-2021 07:41:35.822 INFO [main] org.apache.catalina.startup.VersionLoggerListener.log Java Home: /usr/local/openjdk-11
21-Dec-2021 07:41:35.822 INFO [main] org.apache.catalina.startup.VersionLoggerListener.log JVM Version: 11.0.13+8
21-Dec-2021 07:41:35.822 INFO [main] org.apache.catalina.startup.VersionLoggerListener.log JVM Vendor: Oracle Corporation
21-Dec-2021 07:41:35.822 INFO [main] org.apache.catalina.startup.VersionLoggerListener.log CATALINA_BASE: /usr/local/tomcat
21-Dec-2021 07:41:35.822 INFO [main] org.apache.catalina.startup.VersionLoggerListener.log CATALINA_HOME: /usr/local/tomcat
21-Dec-2021 07:41:35.829 INFO [main] org.apache.catalina.startup.VersionLoggerListener.log Command line argument: --add-opens=java.base/java.lang=ALL-UNNAMED
21-Dec-2021 07:41:35.829 INFO [main] org.apache.catalina.startup.VersionLoggerListener.log Command line argument: --add-opens=java.base/java.io=ALL-UNNAMED
21-Dec-2021 07:41:35.829 INFO [main] org.apache.catalina.startup.VersionLoggerListener.log Command line argument: --add-opens=java.base/java.util=ALL-UNNAMED
21-Dec-2021 07:41:35.829 INFO [main] org.apache.catalina.startup.VersionLoggerListener.log Command line argument: --add-opens=java.base/java.util.concurrent=ALL-UNNAMED
21-Dec-2021 07:41:35.829 INFO [main] org.apache.catalina.startup.VersionLoggerListener.log Command line argument: --add-opens=java.rmi/sun.rmi.transport=ALL-UNNAMED
21-Dec-2021 07:41:35.829 INFO [main] org.apache.catalina.startup.VersionLoggerListener.log Command line argument: -Djava.util.logging.config.file=/usr/local/tomcat/conf/logging.properties
21-Dec-2021 07:41:35.829 INFO [main] org.apache.catalina.startup.VersionLoggerListener.log Command line argument: -Djava.util.logging.manager=org.apache.juli.ClassLoaderLogManager
21-Dec-2021 07:41:35.829 INFO [main] org.apache.catalina.startup.VersionLoggerListener.log Command line argument: -Djdk.tls.ephemeralDHKeySize=2048
21-Dec-2021 07:41:35.829 INFO [main] org.apache.catalina.startup.VersionLoggerListener.log Command line argument: -Djava.protocol.handler.pkgs=org.apache.catalina.webresources
21-Dec-2021 07:41:35.829 INFO [main] org.apache.catalina.startup.VersionLoggerListener.log Command line argument: -Dorg.apache.catalina.security.SecurityListener.UMASK=0027
21-Dec-2021 07:41:35.830 INFO [main] org.apache.catalina.startup.VersionLoggerListener.log Command line argument: -Dignore.endorsed.dirs=
21-Dec-2021 07:41:35.830 INFO [main] org.apache.catalina.startup.VersionLoggerListener.log Command line argument: -Dcatalina.base=/usr/local/tomcat
21-Dec-2021 07:41:35.830 INFO [main] org.apache.catalina.startup.VersionLoggerListener.log Command line argument: -Dcatalina.home=/usr/local/tomcat
21-Dec-2021 07:41:35.830 INFO [main] org.apache.catalina.startup.VersionLoggerListener.log Command line argument: -Djava.io.tmpdir=/usr/local/tomcat/temp
21-Dec-2021 07:41:35.831 INFO [main] org.apache.catalina.core.AprLifecycleListener.lifecycleEvent Loaded Apache Tomcat Native library [1.2.31] using APR version [1.7.0].
21-Dec-2021 07:41:35.832 INFO [main] org.apache.catalina.core.AprLifecycleListener.lifecycleEvent APR capabilities: IPv6 [true], sendfile [true], accept filters [false], random [true], UDS [true].
21-Dec-2021 07:41:35.833 INFO [main] org.apache.catalina.core.AprLifecycleListener.initializeSSL OpenSSL successfully initialized [OpenSSL 1.1.1k 25 Mar 2021]
21-Dec-2021 07:41:35.979 INFO [main] org.apache.coyote.AbstractProtocol.init Initializing ProtocolHandler ["http-nio-8080"]
21-Dec-2021 07:41:35.990 INFO [main] org.apache.catalina.startup.Catalina.load Server initialization in [268] milliseconds
21-Dec-2021 07:41:36.018 INFO [main] org.apache.catalina.core.StandardService.startInternal Starting service [Catalina]
21-Dec-2021 07:41:36.018 INFO [main] org.apache.catalina.core.StandardEngine.startInternal Starting Servlet engine: [Apache Tomcat/10.0.14]
21-Dec-2021 07:41:36.024 INFO [main] org.apache.catalina.startup.HostConfig.deployWAR Deploying web application archive [/usr/local/tomcat/webapps/ROOT.war]
21-Dec-2021 07:41:36.576 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.
21-Dec-2021 07:41:36.596 INFO [main] org.apache.catalina.startup.HostConfig.deployWAR Deployment of web application archive [/usr/local/tomcat/webapps/ROOT.war] has finished in [572] ms
21-Dec-2021 07:41:36.599 INFO [main] org.apache.coyote.AbstractProtocol.start Starting ProtocolHandler ["http-nio-8080"]
21-Dec-2021 07:41:36.607 INFO [main] org.apache.catalina.startup.Catalina.start Server startup in [617] milliseconds
But there is no luck when I try to view the website through the browser. Can anyone tell me what am I missing?
The problem is the fact that you are trying to run the Spring Boot 2.x application on Tomcat 10 which is not yet supported. One of the biggest changes of the Tomcat 10 was
Migration from Java EE to Jakarta EE as part of the transfer of Java EE to the Eclipse Foundation, the primary package for all implemented APIs has changed from javax.* to jakarta.*. This will almost certainly require code changes to enable applications to migrate from Tomcat 9 and earlier to Tomcat 10 and later.
So all of the APIs which are used by Spring Framework are based on the older javax.*
and new jakarta.*
will be supported in Spring Framework 6 and Spring Boot 3 late 2022 )) More details here
What you need to do is just adjust the Dockerfile to run the application of the Tomcat 9. This one will work if you are on Java 17
FROM tomcat:9.0-jre17-temurin
ADD WebTutorial.war /usr/local/tomcat/webapps/ROOT.war
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With