docker制作tomcat鏡像方法及異常處理
【說明】
制作tomcat鏡像,需要在官網(wǎng)下載tomcat binary壓縮包。
tomcat官網(wǎng):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
- 在當(dāng)前目錄下創(chuàng)建一個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="zhongjianjian@ceair.com"
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構(gòu)建鏡像
# 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="external nofollow" rel="icon" type="image/x-icon" />
<link href="tomcat.css" rel="external nofollow" rel="stylesheet" type="text/css" />
</head>
<body>
<div id="wrapper">
<div id="navigation" class="curved container">
<span id="nav-home"><a rel="external nofollow" >Home</a></span>
<span id="nav-hosts"><a href="/docs/" rel="external nofollow" >Documentation</a></span>
<span id="nav-config"><a href="/docs/config/" rel="external nofollow" >Configuration</a></span>
<span id="nav-examples"><a href="/examples/" rel="external nofollow" >Examples</a></span>
<span id="nav-wiki"><a rel="external nofollow" >Wiki</a></span>
<span id="nav-lists"><a rel="external nofollow" >Mailing Lists</a></span>
<span id="nav-help"><a rel="external nofollow" >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.
解決方案:程序沒權(quán)限執(zhí)行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
解決方案:構(gòu)建鏡像用的tomcat.tar.gz是src源碼包,需要使用binary包。
總結(jié)
到此這篇關(guān)于docker制作tomcat鏡像方法及異常處理的文章就介紹到這了,更多相關(guān)docker制作tomcat鏡像內(nèi)容請搜索腳本之家以前的文章或繼續(xù)瀏覽下面的相關(guān)文章希望大家以后多多支持腳本之家!
相關(guān)文章
詳解如何修改 Docker 默認(rèn)網(wǎng)橋地址
這篇文章主要介紹了詳解如何修改 Docker 默認(rèn)網(wǎng)橋地址,小編覺得挺不錯的,現(xiàn)在分享給大家,也給大家做個參考。一起跟隨小編過來看看吧2017-05-05
docker安裝mariadb并在本地持久化數(shù)據(jù)方式
這篇文章主要介紹了docker安裝mariadb并數(shù)據(jù)持久化方式,具有很好的參考價值,希望對大家有所幫助,如有錯誤或未考慮完全的地方,望不吝賜教2025-06-06
使用Vscode結(jié)合docker進(jìn)行開發(fā)的詳細(xì)過程
這篇文章主要介紹了如何使用Vscode結(jié)合docker進(jìn)行開發(fā),在本文中,我將提供一個在 Node 環(huán)境中運行的 JavaScript 應(yīng)用程序示例。閱讀在容器內(nèi)開發(fā)以獲取所有技術(shù)堆棧的詳細(xì)文檔,需要的朋友可以參考下2021-07-07
使用Docker部署的基于binlog實現(xiàn)Mysql8的操作方法
MySQL 基于?Binlog?的主從復(fù)制(Master-Slave Replication)是 MySQL 數(shù)據(jù)庫中實現(xiàn)數(shù)據(jù)復(fù)制的一種機制,這篇文章主要介紹了使用Docker部署的基于binlog實現(xiàn)Mysql8,需要的朋友可以參考下2025-01-01

