docker制作tomcat镜像方法
【说明】
制作tomcat镜像,需要在官网下载tomcat binary压缩包。
tomcat官网:https://tomcat.apache.org/download-90.cgi
【配置方法】
- 新建一个/opt/tomcat/目录,将下载tomcat与jdk安装包上传并解压缩:
# mkdir -p /opt/tomcat; cd /opt/tomcat
#ls
apache-tomcat-9.0.93.tar.gz jdk-8u144-linux-x64.tar.gz Kylin-Server-V10-SP3-2403-Release-Docker-init-20240426-X86_64.tar.xz
# tar -zxvf apache-tomcat-9.0.93.tar.gz
# tar -zxvf jdk-8u144-linux-x64.tar.gz
- 提供制作镜像的base镜像,此次使用Kylin-Server-V10-SP3-2403-Release-Docker-init-20240426-X86_64.tar.xz
# docker load -i Kylin-Server-V10-SP3-2403-Release-Docker-init-20240426-X86_64.tar.xz
# docker images
[root@localhost tomcat]# docker images
REPOSITORY TAG IMAGE ID CREATED SIZE
cr.kylinos.cn/v10sp3-2403/kylin-server-v10-sp3-2403-general-alpha20-x86_64-init 202405 6bd24f9f88c3 3 months ago 246MB
- 在当前目录下创建一个Dockerfile文件
# vim Dockfile
FROM cr.kylinos.cn/v10sp3-2403/kylin-server-v10-sp3-2403-general-alpha20-x86_64-init:202405
MAINTAINER xiongle
LABEL description="This is tomcat9.0.93 image" \
Tomcat.Version="9.0.93" \
OS.Version="Kylin-Server-V10-SP3-2403" \
JDK.Version="OpenJDK Runtime Environment (Alibaba Dragonwell 8.7.7) (build 1.8.0_292-b01)" \
mail="[email protected]"
ADD jdk-8u144-linux-x64.tar.gz /opt/
ADD apache-tomcat-9.0.93.tar.gz /opt/
ENV JAVA_HOME /opt/jdk1.8.0_144
ENV CLASSPATH $JAVA_HOME/lib/dt.jar:$JAVA_HOME/lib/tools.jar
ENV CATALINA_HOME /opt/apache-tomcat-9.0.93
ENV CATALINA_BASE /opt/apache-tomcat-9.0.93
ENV PATH $PATH:$JAVA_HOME/bin:$CATALINA_HOME/lib:$CATALINA_HOME/bin
RUN chmod +x /opt/apache-tomcat-9.0.93/bin/catalina.sh
EXPOSE 8080
CMD /opt/apache-tomcat-9.0.93/bin/catalina.sh run
- 通过docker build构建镜像
# docker build -t tomcat:9.0.93 .
- 运行容器
# docker images
REPOSITORY TAG IMAGE ID CREATED SIZE
tomcat 9.0.93 3468b888f5b1 2 hours ago 639MB
cr.kylinos.cn/v10sp3-2403/kylin-server-v10-sp3-2403-general-alpha20-x86_64-init 202405 6bd24f9f88c3 3 months ago 246MB
# docker run -d --name test1 -p 8060:8080 tomcat:9.0.93
# docker logs test1
Using CATALINA_BASE: /opt/apache-tomcat-9.0.93
Using CATALINA_HOME: /opt/apache-tomcat-9.0.93
Using CATALINA_TMPDIR: /opt/apache-tomcat-9.0.93/temp
Using JRE_HOME: /opt/jdk1.8.0_144
Using CLASSPATH: /opt/apache-tomcat-9.0.93/bin/bootstrap.jar:/opt/apache-tomcat-9.0.93/bin/tomcat-juli.jar
Using CATALINA_OPTS:
02-Sep-2024 15:20:22.501 INFO [main] org.apache.catalina.startup.VersionLoggerListener.log Server version name: Apache Tomcat/9.0.93
02-Sep-2024 15:20:22.503 INFO [main] org.apache.catalina.startup.VersionLoggerListener.log Server built: Aug 2 2024 21:24:59 UTC
02-Sep-2024 15:20:22.504 INFO [main] org.apache.catalina.startup.VersionLoggerListener.log Server version number: 9.0.93.0
02-Sep-2024 15:20:22.504 INFO [main] org.apache.catalina.startup.VersionLoggerListener.log OS Name: Linux
02-Sep-2024 15:20:22.504 INFO [main] org.apache.catalina.startup.VersionLoggerListener.log OS Version: 4.19.90-52.22.v2207.ky10.x86_64
# docker ps -a
CONTAINER ID IMAGE COMMAND CREATED STATUS PORTS NAMES
40e062400da6 tomcat:9.0.93 "/bin/sh -c '/opt/ap…" 2 hours ago Up 2 hours 0.0.0.0:8060->8080/tcp test1
# curl localhost:8060
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8" />
<title>Apache Tomcat/9.0.93</title>
<link href="favicon.ico" rel="icon" type="image/x-icon" />
<link href="tomcat.css" rel="stylesheet" type="text/css" />
</head>
<body>
<div id="wrapper">
<div id="navigation" class="curved container">
<span id="nav-home"><a href="https://tomcat.apache.org/">Home</a></span>
<span id="nav-hosts"><a href="/docs/">Documentation</a></span>
<span id="nav-config"><a href="/docs/config/">Configuration</a></span>
<span id="nav-examples"><a href="/examples/">Examples</a></span>
<span id="nav-wiki"><a href="https://cwiki.apache.org/confluence/display/TOMCAT/">Wiki</a></span>
<span id="nav-lists"><a href="https://tomcat.apache.org/lists.html">Mailing Lists</a></span>
<span id="nav-help"><a href="https://tomcat.apache.org/findhelp.html">Find Help</a></span>
<br class="separator" />
</div>
<div id="asf-box">
<h1>Apache Tomcat/9.0.93</h1>
</div>
<div id="upper" class="curved container">
<div id="congrats" class="curved container">
<h2>If you're seeing this, you've successfully installed Tomcat. Congratulations!</h2>
</div>
【异常处理】
问题1:/opt/apache-tomact-9.0.50/bin/catalina.sh: permission denied.
解决方案:程序没权限执行catalina.sh脚本。在Dockerfile中新增一行:RUN chmod +x /opt/apache-tomcat-9.0.93/bin/catalina.sh
问题2:Error: Could not find or load main class org.apache.catalina.startup.Bootstrap
解决方案:构建镜像用的tomcat.tar.gz是src源码包,需要使用binary包。
标签:opt,tar,tomcat,apache,镜像,docker,9.0,93 From: https://blog.csdn.net/weixin_43948680/article/details/141929860