DockerFile actual combat tomcat image

Actual combat: Tomcat mirroring

1. First, prepare the image tomcat compressed package and jdk compressed package.
insert image description here
2. Write the dockerfile file, which is officially named Dockerfile. When building, it will automatically search for this file, so there is no need to specify -f

FROM centos
MAINTAINER liulihui<[email protected]>

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

ADD jdk-8u231-linux-x64.tar.gz /usr/local/
ADD apache-tomcat-8.5.50.tar.gz /usr/local/

ENV MYPATH /usr/local
WORKDIR $MYPATH

ENV JAVA_HOME /usr/local/jdk1.8.0_231
ENV CLASSPATH $JAVA_HOME/lib/dt.jar:$JAVA_HOME/lib/tools.jar

ENV CATALINA_HOME /usr/local/apache-tomcat-8.5.50
ENV CATALINA_BASH /usr/local/apache-tomcat-8.5.50
ENV PATH $PATH:$JAVA_HOME/bin:$CATALINA_HOME/lib:$CATALINA_HOME/bin

EXPOSE 8080
CMD /usr/local/apache-tomcat-8.5.50/bin/startup.sh && tail -f /usr/local/apache-tomcat-8.5.50/logs/catalina.out

3. Build a mirror image

[root@liulihui tomcat]# docker build -t diytomcat .

4. Start mirroring

# 查看镜像 
[root@liulihui tomcat]# docker images
REPOSITORY            TAG       IMAGE ID       CREATED          SIZE
diytomcat             latest    151a2aa6587a   22 seconds ago   649MB

# 启动镜像 diytomcat
[root@liulihui tomcat]# docker run -d -p 9090:8080 --name liulihuitomcat -v /home/liulihui/build/tomcat/test:/usr/local/apache-tomcat-8.5.50/webapps/test -v /home/liulihui/build/tomcat/tomcatlogs/:/usr/local/apache-tomcat-8.5.50/logs diytomcat

5. Access test
insert image description here
6. Publish the image (because of the mount, you can publish the project directly by writing it locally!), and write the web.xml file

<?xml version="1.0" encoding="UTF-8"?>
<web-app xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
    xmlns="http://java.sun.com/xml/ns/javaee"
    xmlns:web="http://java.sun.com/xml/ns/javaee/web-app_2_5.xsd"
    xsi:schemaLocation="http://java.sun.com/xml/ns/javaee http://java.sun.com/xml/ns/javaee/web-app_2_5.xsd"
    id="WebApp_ID" version="2.5">
    
    
</web-app>

insert image description here
Test writing index.jsp

<%@ page language="java" contentType="text/html; charset=UTF-8"
    pageEncoding="UTF-8"%>
<!DOCTYPE html>
<html>
<head>
<meta charset="utf-8">
<title>hello liulihui</title>
</head>
<body>
Hello World!<br/>
<%
System.out.println("----- my test web logs--------");
%>
</body>
</html>

insert image description here
Access: http://ip:9090/test/
insert image description here

It is found that the deployment is completed, and you can directly access ok!

Guess you like

Origin blog.csdn.net/liulihui1988/article/details/128293354