Cloud Native 16 min read

Deploy Tomcat and SpringBoot Apps with Docker: From Image Build to Production

This guide walks through migrating services from Alibaba Cloud to AWS by containerizing Tomcat and SpringBoot applications with Docker, covering environment checks, Dockerfile creation, image building, container deployment, troubleshooting, and best‑practice summaries for reliable production rollout.

MaGe Linux Operations
MaGe Linux Operations
MaGe Linux Operations
Deploy Tomcat and SpringBoot Apps with Docker: From Image Build to Production

Introduction

Due to an internal migration from Alibaba Cloud to Amazon Web Services, the team needed to resolve packaging issues on Windows remote machines and move services to Docker images, resulting in faster performance.

Basic Tomcat Image Deployment

Check the OS and Docker service status, verify Docker version, pull the Tomcat 8.5.46‑jdk8‑openjdk image, create a data directory, and run the container:

[root@VM-12-2-opencloudos local]# cat /etc/os-release
NAME="OpenCloudOS"
VERSION="8.6"
ID="opencloudos"
ID_LIKE="rhel fedora"
VERSION_ID="8.6"
PLATFORM_ID="platform:oc8"
PRETTY_NAME="OpenCloudOS 8.6"

[root@VM-12-2-opencloudos local]# systemctl status docker
● docker.service - Docker Application Container Engine
   Loaded: loaded (/usr/lib/systemd/system/docker.service; enabled; vendor preset: disabled)
   Active: active (running) since Wed 2023-11-01 21:57:27 CST; 3 weeks 2 days ago

[root@VM-12-2-opencloudos local]# docker version
Client: Docker Engine - Community
 Version: 24.0.7
 API version: 1.43
 Server: Docker Engine - Community
 Engine:
  Version: 24.0.7
  API version: 1.43 (minimum version 1.12)

[root@VM-12-2-opencloudos local]# docker pull tomcat:8.5.46-jdk8-openjdk
8.5.46-jdk8-openjdk: Pulling from library/tomcat
... (layers pulled) ...
Status: Downloaded newer image for tomcat:8.5.46-jdk8-openjdk

[root@VM-12-2-opencloudos local]# mkdir -p /data/tomcat/data
[root@VM-12-2-opencloudos local]# chmod -R 777 /data/tomcat/

[root@VM-12-2-opencloudos local]# docker run -d --name my_web --restart always -p 8080:8080 -v /data/tomcat/data:/usr/local/tomcat/webapps/ROOT/ tomcat:8.5.46-jdk8-openjdk
5a8bf43b2c1568d0d72477ae4a8846421533b66a5bd946ac27978980efe908f6

[root@VM-12-2-opencloudos local]# docker ps
CONTAINER ID   IMAGE                        COMMAND                  CREATED         STATUS         PORTS                                                  NAMES
5a8bf43b2c15   tomcat:8.5.46-jdk8-openjdk   "catalina.sh run"        2 minutes ago   Up 2 minutes   0.0.0.0:8080->8080/tcp, :::8080->8080/tcp              my_web

Enterprise Practice – Building a Custom Tomcat Project Image

Select Tomcat 8.5.46‑jdk8‑openjdk and JDK 1.8.0_92, upload the tar.gz files, and write a Dockerfile that adds the JDK and Tomcat, sets environment variables, exposes port 8080, and defines the entrypoint.

# Dockerfile
FROM centos:7
ENV TZ=Asia/Shanghai
ADD jdk1.8.0_92.tar.gz /usr/local/tomcat
ADD tomcat9.tar.gz /usr/local/tomcat
RUN rm -rf /usr/local/tomcat/tomcat9/webapps/*
COPY ROOT.war /usr/local/tomcat/tomcat9/webapps/
RUN yum -y install vim
ENV MYPATH /usr/local
WORKDIR $MYPATH
ENV JAVA_HOME /usr/local/tomcat/jdk1.8.0_92
ENV CATALINA_HOME /usr/local/tomcat/tomcat9
ENV CATALINA_BASE /usr/local/tomcat/tomcat9
ENV PATH $PATH:$JAVA_HOME/bin:$CATALINA_HOME/lib:$CATALINA_HOME/bin
VOLUME ["/usr/local/zhixiao/file/","/usr/local/tomcat/tomcat9/webapps/"]
ENTRYPOINT ["/usr/local/tomcat/tomcat9/bin/catalina.sh","run"]
EXPOSE 8080

Build and run the image:

docker build -t zxht:1.0 .
docker run -d --name zxht -p 8080:8080 zxht:1.0

Inspect logs inside the container to confirm JVM parameters are applied and the application starts successfully.

Enterprise Practice – Deploying a SpringBoot Application with Docker

Create a Dockerfile that adds JDK 1.8.0_92, copies the built JAR, sets JAVA_OPTS, exposes port 8080, and uses an ENTRYPOINT to launch the JAR.

# Dockerfile
FROM centos:7
ADD jdk1.8.0_92.tar.gz /usr/local/jdk
WORKDIR /opt
ENV JAVA_HOME /usr/local/jdk/jdk1.8.0_92
ENV CLASSPATH $JAVA_HOME/lib/dt.jar:$JAVA_HOME/lib/tools.jar
ENV PATH $PATH:$JAVA_HOME/bin
VOLUME /tmp
COPY *.jar /opt/app.jar
EXPOSE 8080
ENV JAVA_OPTS "\
 -server \
 -Xss256k \
 -XX:MaxMetaspaceSize=256m \
 -XX:+UseG1GC \
 -XX:+AlwaysPreTouch \
 -XX:-ResizePLAB \
 -XX:+ParallelRefProcEnabled \
 -XX:+ExplicitGCInvokesConcurrent \
 -XX:MaxGCPauseMillis=200 \
 -XX:ParallelGCThreads=4 \
 -XX:ConcGCThreads=2 \
 -Xmn768m \
 -Xmx2g \
 -Xms2g \
 -XX:+PrintGCDetails \
 -XX:+PrintTenuringDistribution \
 -XX:+PrintGCTimeStamps \
 -XX:+HeapDumpOnOutOfMemoryError \
 -XX:HeapDumpPath=/opt \
 -XX:+UseGCLogFileRotation \
 -XX:NumberOfGCLogFiles=5 \
 -XX:GCLogFileSize=20M"
ENTRYPOINT java ${JAVA_OPTS} -jar /opt/app.jar

Build and run:

docker build -t pc:1.0 .
docker run -d -p 8080:8080 --name pc pc:1.0

Problem Review

Common issues such as XML parsing errors (e.g., "only whitespace content allowed before start tag") and mixed Groovy/Java project packaging failures are resolved by cleaning the Maven repository, deleting problematic JAR directories, and ensuring consistent build configurations.

Conclusion

Dockerfile authoring defines the build steps, environment, and runtime commands; docker build creates the image; docker run starts the container; network and port configuration enable external access; data volumes handle persistence; monitoring logs ensure stability; and regular updates keep the environment current.

Original Source

Signed-in readers can open the original source through BestHub's protected redirect.

Sign in to view source
Republication Notice

This article has been distilled and summarized from source material, then republished for learning and reference. If you believe it infringes your rights, please contactadmin@besthub.devand we will review it promptly.

DevOpscontainerizationSpringBootTomcat
MaGe Linux Operations
Written by

MaGe Linux Operations

Founded in 2009, MaGe Education is a top Chinese high‑end IT training brand. Its graduates earn 12K+ RMB salaries, and the school has trained tens of thousands of students. It offers high‑pay courses in Linux cloud operations, Python full‑stack, automation, data analysis, AI, and Go high‑concurrency architecture. Thanks to quality courses and a solid reputation, it has talent partnerships with numerous internet firms.

0 followers
Reader feedback

How this landed with the community

Sign in to like

Rate this article

Was this worth your time?

Sign in to rate
Discussion

0 Comments

Thoughtful readers leave field notes, pushback, and hard-won operational detail here.