Docker7:Docker部署Tomcat

Docker7:Docker部署Tomcat

Created
Nov 16, 2021 08:16 AM
Last Edited
Last updated December 2, 2021
Tags

1. 测试

# 官方方式,用完即删容器,一般用于测试 docker run -it --rm tomcat:9.0
root@docker:/home/henggao/Desktop# docker run -it --rm tomcat:9.0 Unable to find image 'tomcat:9.0' locally 9.0: Pulling from library/tomcat bb7d5a84853b: Already exists f02b617c6a8c: Already exists d32e17419b7e: Already exists c9d2d81226a4: Already exists fab4960f9cd2: Already exists da1c1e7baf6d: Already exists 1d2ade66c57e: Already exists ea2ad3f7cb7c: Already exists d1b97f105b7d: Pull complete f04db345efb3: Pull complete Digest: sha256:2a335cf8a9f43a885227cc3cb927dccadcd22e075d4f2b0bc1e6d5668e744fa0 Status: Downloaded newer image for tomcat:9.0 Using CATALINA_BASE: /usr/local/tomcat Using CATALINA_HOME: /usr/local/tomcat Using CATALINA_TMPDIR: /usr/local/tomcat/temp Using JRE_HOME: /usr/local/openjdk-11 Using CLASSPATH: /usr/local/tomcat/bin/bootstrap.jar:/usr/local/tomcat/bin/tomcat-juli.jar Using CATALINA_OPTS: NOTE: Picked up JDK_JAVA_OPTIONS: --add-opens=java.base/java.lang=ALL-UNNAMED --add-opens=java.base/java.io=ALL-UNNAMED --add-opens=java.base/java.util=ALL-UNNAMED --add-opens=java.base/java.util.concurrent=ALL-UNNAMED --add-opens=java.rmi/sun.rmi.transport=ALL-UNNAMED 16-Nov-2021 11:35:32.141 INFO [main] org.apache.catalina.startup.VersionLoggerListener.log Server version name: Apache Tomcat/9.0.55 16-Nov-2021 11:35:32.144 INFO [main] org.apache.catalina.startup.VersionLoggerListener.log Server built: Nov 10 2021 08:26:45 UTC 16-Nov-2021 11:35:32.145 INFO [main] org.apache.catalina.startup.VersionLoggerListener.log Server version number: 9.0.55.0 16-Nov-2021 11:35:32.145 INFO [main] org.apache.catalina.startup.VersionLoggerListener.log OS Name: Linux 16-Nov-2021 11:35:32.145 INFO [main] org.apache.catalina.startup.VersionLoggerListener.log OS Version: 5.11.0-40-generic 16-Nov-2021 11:35:32.145 INFO [main] org.apache.catalina.startup.VersionLoggerListener.log Architecture: amd64 16-Nov-2021 11:35:32.145 INFO [main] org.apache.catalina.startup.VersionLoggerListener.log Java Home: /usr/local/openjdk-11 16-Nov-2021 11:35:32.145 INFO [main] org.apache.catalina.startup.VersionLoggerListener.log JVM Version: 11.0.13+8 16-Nov-2021 11:35:32.145 INFO [main] org.apache.catalina.startup.VersionLoggerListener.log JVM Vendor: Oracle Corporation 16-Nov-2021 11:35:32.145 INFO [main] org.apache.catalina.startup.VersionLoggerListener.log CATALINA_BASE: /usr/local/tomcat 16-Nov-2021 11:35:32.145 INFO [main] org.apache.catalina.startup.VersionLoggerListener.log CATALINA_HOME: /usr/local/tomcat 16-Nov-2021 11:35:32.158 INFO [main] org.apache.catalina.startup.VersionLoggerListener.log Command line argument: --add-opens=java.base/java.lang=ALL-UNNAMED 16-Nov-2021 11:35:32.158 INFO [main] org.apache.catalina.startup.VersionLoggerListener.log Command line argument: --add-opens=java.base/java.io=ALL-UNNAMED 16-Nov-2021 11:35:32.158 INFO [main] org.apache.catalina.startup.VersionLoggerListener.log Command line argument: --add-opens=java.base/java.util=ALL-UNNAMED 16-Nov-2021 11:35:32.159 INFO [main] org.apache.catalina.startup.VersionLoggerListener.log Command line argument: --add-opens=java.base/java.util.concurrent=ALL-UNNAMED 16-Nov-2021 11:35:32.159 INFO [main] org.apache.catalina.startup.VersionLoggerListener.log Command line argument: --add-opens=java.rmi/sun.rmi.transport=ALL-UNNAMED 16-Nov-2021 11:35:32.159 INFO [main] org.apache.catalina.startup.VersionLoggerListener.log Command line argument: -Djava.util.logging.config.file=/usr/local/tomcat/conf/logging.properties 16-Nov-2021 11:35:32.159 INFO [main] org.apache.catalina.startup.VersionLoggerListener.log Command line argument: -Djava.util.logging.manager=org.apache.juli.ClassLoaderLogManager 16-Nov-2021 11:35:32.159 INFO [main] org.apache.catalina.startup.VersionLoggerListener.log Command line argument: -Djdk.tls.ephemeralDHKeySize=2048 16-Nov-2021 11:35:32.159 INFO [main] org.apache.catalina.startup.VersionLoggerListener.log Command line argument: -Djava.protocol.handler.pkgs=org.apache.catalina.webresources 16-Nov-2021 11:35:32.160 INFO [main] org.apache.catalina.startup.VersionLoggerListener.log Command line argument: -Dorg.apache.catalina.security.SecurityListener.UMASK=0027 16-Nov-2021 11:35:32.160 INFO [main] org.apache.catalina.startup.VersionLoggerListener.log Command line argument: -Dignore.endorsed.dirs= 16-Nov-2021 11:35:32.160 INFO [main] org.apache.catalina.startup.VersionLoggerListener.log Command line argument: -Dcatalina.base=/usr/local/tomcat 16-Nov-2021 11:35:32.160 INFO [main] org.apache.catalina.startup.VersionLoggerListener.log Command line argument: -Dcatalina.home=/usr/local/tomcat 16-Nov-2021 11:35:32.161 INFO [main] org.apache.catalina.startup.VersionLoggerListener.log Command line argument: -Djava.io.tmpdir=/usr/local/tomcat/temp 16-Nov-2021 11:35:32.165 INFO [main] org.apache.catalina.core.AprLifecycleListener.lifecycleEvent Loaded Apache Tomcat Native library [1.2.31] using APR version [1.7.0]. 16-Nov-2021 11:35:32.166 INFO [main] org.apache.catalina.core.AprLifecycleListener.lifecycleEvent APR capabilities: IPv6 [true], sendfile [true], accept filters [false], random [true], UDS [true]. 16-Nov-2021 11:35:32.166 INFO [main] org.apache.catalina.core.AprLifecycleListener.lifecycleEvent APR/OpenSSL configuration: useAprConnector [false], useOpenSSL [true] 16-Nov-2021 11:35:32.168 INFO [main] org.apache.catalina.core.AprLifecycleListener.initializeSSL OpenSSL successfully initialized [OpenSSL 1.1.1k 25 Mar 2021] 16-Nov-2021 11:35:32.497 INFO [main] org.apache.coyote.AbstractProtocol.init Initializing ProtocolHandler ["http-nio-8080"] 16-Nov-2021 11:35:32.522 INFO [main] org.apache.catalina.startup.Catalina.load Server initialization in [586] milliseconds 16-Nov-2021 11:35:32.575 INFO [main] org.apache.catalina.core.StandardService.startInternal Starting service [Catalina] 16-Nov-2021 11:35:32.575 INFO [main] org.apache.catalina.core.StandardEngine.startInternal Starting Servlet engine: [Apache Tomcat/9.0.55] 16-Nov-2021 11:35:32.588 INFO [main] org.apache.coyote.AbstractProtocol.start Starting ProtocolHandler ["http-nio-8080"] 16-Nov-2021 11:35:32.603 INFO [main] org.apache.catalina.startup.Catalina.start Server startup in [80] milliseconds

2. 拉取Tomcat镜像

2.1 下载

# 1. 下载再启动 docker pull tomcat # 2. 启动运行 docker run -d -p 3355:8080 --name tomcat01 tomcat

2.2 查看浏览器

notion image
  • 部署成功,测试访问没问题
 

2.3分析

# 进入容器 root@docker:/home/henggao/Desktop# docker exec -it tomcat01 /bin/bash # 1. Linux命令少了 # 2. 没有webapps。阿里云镜像的原因。默认是最小的镜像,所有不必要的都剔除掉了 # 保证最小的可运行环境
 

2.4 修改

# 将webapps.dist中文件拷贝到webapps root@525fcd4bc627:/usr/local/tomcat# cp -r webapps.dist/* webapps
root@525fcd4bc627:/usr/local/tomcat# cd webapps root@525fcd4bc627:/usr/local/tomcat/webapps# ls root@525fcd4bc627:/usr/local/tomcat/webapps# cd .. root@525fcd4bc627:/usr/local/tomcat# cd webapps.dist/ root@525fcd4bc627:/usr/local/tomcat/webapps.dist# ls ROOT docs examples host-manager manager root@525fcd4bc627:/usr/local/tomcat/webapps.dist# cd .. root@525fcd4bc627:/usr/local/tomcat# cp -r webapps.dist/* webapps root@525fcd4bc627:/usr/local/tomcat# cd webapps root@525fcd4bc627:/usr/local/tomcat/webapps# ls ROOT docs examples host-manager manager root@525fcd4bc627:/usr/local/tomcat/webapps#
 

2.5 刷新浏览器

notion image