spring-boottomcatdockerfile

Unable to start spring boot war file from tomcat container


I am using the official tomcat latest docker image. I have created a docker file to use this tomcat image and deploy the war files directly to tomcat webapps. When I run this docker image to start the container the spring boot app is not starting up as I don't see any application startup logs. The same war file when deployed to a local tomcat server is working fine but only when I use sudo to run the catalina.sh run command.

Here is the docker file I used:

##### Use the official Tomcat base image
FROM tomcat:latest

##### Env variable for log path
ENV LOG_PATH=/usr/local/tomcat/logs


##### Copy the WAR file into the webapps directory
COPY service-2.1.6.war /usr/local/tomcat/webapps/

##### Create necessary directories for Tomcat web applications
RUN mv /usr/local/tomcat/webapps.dist/* /usr/local/tomcat/webapps/

##### Set the environment variable for the active Spring profile
#####ENV SPRING_PROFILES_ACTIVE=prod

##### Copy the tomcat-users.xml file to configure the manager users
COPY tomcat-users.xml /usr/local/tomcat/conf/tomcat-users.xml
COPY context.xml /usr/local/tomcat/webapps/manager/META-INF/context.xml

#####Install sudo
RUN apt-get update && apt-get install -y sudo

##### Start Tomcat with sudo
#####CMD ["sudo", "/usr/local/tomcat/bin/catalina.sh", "run"]

Tomcat startup logs from docker container: enter image description here

Tomcat startup logs from local tomcat setup: enter image description here

What could be wrong or missing here?


Solution

    1. The problem was the base tomcat image used for starting the container. My spring boot app was using spring boot version 2.4.5 built using jdk17 version and I was using tomcat:latest image which is using jdk21.
    2. The key here is to have the same version of jdk used to build the war file and tomcat.
    3. You can check what JDK version the tomcat image uses by checking its layer details and figuring out the JDK version as shown in the image below. I fixed my problem by using a tomcat image which supports JDK17 which in my case was 8.5.98-jre17-temurin.
    4. I was also able to run it with 9.0.90-jre17-temurin-jammy as this also used JDK17.

    enter image description here