#docker pull daocloud.io/library/tomcat:8.5.19
以此镜像为基础,运行并进入容器。修改 tomcat 的首页,要求首页内容中包含自己的姓名。
以这个修改后的tomcat为新的模板生成tomcat新镜像,镜像名为 tomcat/5.27。
参考命令:#docker commit -a="hll" -m="hll tomcat" 容器ID hll/tomcat:5.27
要求:
(1)查看镜像
(2)运行新生成的镜像
端口号随机。在浏览器中查看对应的页面。
[root@localhost ~]# docker pull daocloud.io/library/tomcat:8.5.19
运行 -P 大 P 为系统自动分配端口 小 p 需手动指定
[root@localhost ~]# docker run -it -P 3c42844f3642
Using CATALINA_BASE: /usr/local/tomcat
Using CATALINA_HOME: /usr/local/tomcat
Using CATALINA_TMPDIR: /usr/local/tomcat/temp
Using JRE_HOME: /docker-java-home/jre
Using CLASSPATH: /usr/local/tomcat/bin/bootstrap.jar:/usr/local/tomcat/bin/tomcat-juli.jar
03-Jun-2024 11:31:34.322 INFO [main] org.apache.catalina.startup.VersionLoggerListener.log Server version: Apache Tomcat/8.5.19
03-Jun-2024 11:31:34.323 INFO [main] org.apache.catalina.startup.VersionLoggerListener.log Server built: Jul 24 2017 21:01:14 UTC
03-Jun-2024 11:31:34.323 INFO [main] org.apache.catalina.startup.VersionLoggerListener.log Server number: 8.5.19.0
03-Jun-2024 11:31:34.323 INFO [main] org.apache.catalina.startup.VersionLoggerListener.log OS Name: Linux
#启动后 ctrl+q+p 临时退出容器
查看容器
[root@localhost ~]# docker ps
CONTAINER ID IMAGE COMMAND CREATED STATUS PORTS NAMES
bc1696321d22 3c42844f3642 "catalina.sh run" 3 minutes ago Up 3 minutes 0.0.0.0:32768->8080/tcp mystifying_khayyam
tomcat 首页原图
首先要找到首页文件位置
#回到 tomcat 容器内
[root@localhost ~]# docker exec -it bc1696321d22 /bin/bash
#当前位置
root@bc1696321d22:/usr/local/tomcat# pwd
/usr/local/tomcat
#查看当前位置目录
root@bc1696321d22:/usr/local/tomcat# ls
LICENSE RELEASE-NOTES bin include logs temp work
NOTICE RUNNING.txt conf lib native-jni-lib webapps
#进入 webapps 目录 查看当前位置目录
root@bc1696321d22:/usr/local/tomcat# cd webapps/
root@bc1696321d22:/usr/local/tomcat/webapps# ls
ROOT docs examples host-manager manager
#查看 ROOT 发现目标 index.jsp
root@bc1696321d22:/usr/local/tomcat/webapps# ls ROOT/
RELEASE-NOTES.txt bg-button.png bg-nav.png index.jsp tomcat.gif
WEB-INF bg-middle.png bg-upper.png tomcat-power.gif tomcat.png
asf-logo-wide.svg bg-nav-item.png favicon.ico tomcat.css tomcat.svg
修改首页(首页包含自己的姓名)
root@bc1696321d22:/usr/local/tomcat/webapps# echo "test_name 张三" > ROOT/index.jsp
不识别中文名字用英文填入
root@bc1696321d22:/usr/local/tomcat/webapps# read escape sequence
修改后的tomcat为新的模板生成tomcat新镜像,镜像名为tomcat/5.27
[root@localhost ~]# docker ps
CONTAINER ID IMAGE COMMAND CREATED STATUS PORTS NAMES
bc1696321d22 3c42844f3642 "catalina.sh run" 37 minutes ago Up 37 minutes 0.0.0.0:32768->8080/tcp cocky_murdock
[root@localhost ~]# docker commit -a="22wl-1" -m="22wl-1-tomcat" bc1696321d22 22wl/tomcat:5.30
sha256:49795c698afc3aebb699406b7c39f8fcaeb22e63e8bd1cb4b277083fef50627d
修改了首页的内容,并生成新的镜像。尝试运行新镜像,观察访问的结果
[root@localhost ~]# docker run -it -P 49795c698afc
Using CATALINA_BASE: /usr/local/tomcat
Using CATALINA_HOME: /usr/local/tomcat
Using CATALINA_TMPDIR: /usr/local/tomcat/temp
Using JRE_HOME: /docker-java-home/jre
Using CLASSPATH: /usr/local/tomcat/bin/bootstrap.jar:/usr/local/tomcat/bin/tomcat-juli.jar
22-May-2024 16:13:34.646 INFO [main] org.apache.catalina.startup.VersionLoggerListener.log Server version: Apache Tomcat/8.5.19
#ctrl+q+p
看到运行的容器
[root@localhost ~]# docker ps
CONTAINER ID IMAGE COMMAND CREATED STATUS PORTS NAMES
037811c91a86 49795c698afc "catalina.sh run" 6 minutes ago Up 6 minutes 0.0.0.0:32769->8080/tcp suspicious_neumann
bc1696321d22 3c42844f3642 "catalina.sh run" About an hour ago Up About an hour 0.0.0.0:32768->8080/tcp cocky_murdock