Docker Deployment Project - Demo tomcat

0. Relevant File

1. Write Dockerfile

We will place the apache-tomcat-9.0.73.tar.gz and jdk-8u361-linux-x64.tar.gz files in the same folder.
And in this folder, write the Dockerfile file, with the specific configuration as follows:

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
FROM centos:7
MAINTAINER hardyhu<1243971719@qq.com>

COPY readme.txt /usr/local/readme.txt

ADD jdk-8u361-linux-x64.tar.gz /usr/local/
ADD apache-tomcat-9.0.73.tar.gz /usr/local/

RUN yum -y install vim

ENV MYPATH /usr/local
WORKDIR $MYPATH

ENV JAVA_HOME /usr/local/jdk1.8.0_361
ENV CLASSPATH $JAVA_HOME/lib/dt.jar:$JAVA_HOME/lib/tools.jar
ENV CATALINA_HOME /usr/local/apache-tomcat-9.0.73
ENV CATALINA_BASH /usr/local/apache-tomcat-9.0.73
ENV PATH $PATH:$JAVA_HOME/bin:$CATALINA_HOME/lib:$CATALINA_HOME/bin

EXPOSE 8080

CMD /usr/local/apache-tomcat-9.0.73/bin/startup.sh && tail -F /usr/local/apache-tomcat-9.0.73/logs/catalina.out

You can view additional help information in the Dockerfile Help.

Tip: To specify a configuration file other than Dockerfile, you must use the -f option to provide the file name.

2. Build and Run

2.1 Build Image:

1
docker build -t diytomcat .

The -t represents a tag.

You can view more help information on the build command document.

2.2 Run Container:

1
docker run -d -p 9091:8080 --name hardyhutomcat -v /home/hardyhu/build/tomcat/test:/usr/local/apache-tomcat-9.0.73/webapps/test -v /home/hardyhu/build/tomcat/tomcatlogs/:/usr/local/apache-tomcat-9.0.73/logs diytomcat

The -d represents running the container in the background and printing its container ID.
The -v represents binding a mount to volume.

You can view additional help information in the run command document.

2.3 Enter Container

1
docker exec -it hardyhutomcat /bin/bash

Docker Deployment Project - Demo tomcat
https://www.hardyhu.cn/2023/04/17/Docker-Deployment-Project-Demo-tomcat/
Author
John Doe
Posted on
April 17, 2023
Licensed under