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?
2
Answers
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
So all of the APIs which are used by Spring Framework are based on the older
javax.*
and newjakarta.*
will be supported in Spring Framework 6 and Spring Boot 3 late 2022 )) More details hereWhat 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
i had similar requirement to migrate from tomcat 9 to tomcat 10 with spring 2.2.4 (java 8),
as we know tomcat 9 is supported with java EE and tomcat 10 onwards JAKARATA EE api.
so only thing as of now we can do is migrate using apache migration tool.
Step 1: after building the war file that is compatable with tomcat 9.
Step 2: download the jar https://dlcdn.apache.org/tomcat/jakartaee-migration/v1.0.0/binaries/jakartaee-migration-1.0.0-shaded.jar copy to some folder
Step 3: run the following the command.
Step 4: done. deploy the new.war to tomcat 10 webapps folder.
may be this is helpful.