我在adoptopenjdk中使用了一个tomcat-9的镜像。docker-compose文件配置如下:
tomcat-server:
image: tomcat:9.0.45-jdk11-adoptopenjdk-hotspot
ports:
- "8081:8080"
volumes:
- /webapp/target/app.war:/usr/local/tomcat/webapps/app.war
environment:
- EUREKA.CLIENT.SERVICEURL.DEFAULTZONE=http://naming-server:8761/eureka
- SPRING.REDIS.HOST=redis-cache-server
当我使用docker-compse文件启动tomcat时,日志显示它不会从提到的8081端口启动。它仍然在8080上启动。详细信息请参见日志。
tomcat-server_1 | 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
tomcat-server_1 | org.apache.catalina.startup.VersionLoggerListener.log Server version name: Apache Tomcat/9.0.45
tomcat-server_1 | org.apache.catalina.startup.VersionLoggerListener.log Server built: Mar 30 2021 10:29:04 UTC
tomcat-server_1 | org.apache.catalina.startup.VersionLoggerListener.log Server version number: 9.0.45.0
tomcat-server_1 | org.apache.catalina.startup.VersionLoggerListener.log OS Name: Linux
tomcat-server_1 | org.apache.catalina.startup.VersionLoggerListener.log OS Version: 5.4.72-microsoft-standard-WSL2
tomcat-server_1 | org.apache.catalina.startup.VersionLoggerListener.log Architecture: amd64
tomcat-server_1 | org.apache.catalina.startup.VersionLoggerListener.log Java Home: /opt/java/openjdk
tomcat-server_1 | org.apache.catalina.startup.VersionLoggerListener.log JVM Version: 11.0.10+9
tomcat-server_1 | org.apache.catalina.startup.VersionLoggerListener.log JVM Vendor: AdoptOpenJDK
tomcat-server_1 | org.apache.catalina.startup.VersionLoggerListener.log CATALINA_BASE: /usr/local/tomcat
tomcat-server_1 | org.apache.catalina.startup.VersionLoggerListener.log CATALINA_HOME: /usr/local/tomcat
tomcat-server_1 | org.apache.catalina.startup.VersionLoggerListener.log Command line argument: --add-opens=java.base/java.lang=ALL-UNNAMED
tomcat-server_1 | org.apache.catalina.startup.VersionLoggerListener.log Command line argument: --add-opens=java.base/java.io=ALL-UNNAMED
tomcat-server_1 | org.apache.catalina.startup.VersionLoggerListener.log Command line argument: --add-opens=java.base/java.util=ALL-UNNAMED
tomcat-server_1 | org.apache.catalina.startup.VersionLoggerListener.log Command line argument: --add-opens=java.base/java.util.concurrent=ALL-UNNAMED
tomcat-server_1 | org.apache.catalina.startup.VersionLoggerListener.log Command line argument: --add-opens=java.rmi/sun.rmi.transport=ALL-UNNAMED
tomcat-server_1 | org.apache.catalina.startup.VersionLoggerListener.log Command line argument: -Djava.util.logging.config.file=/usr/local/tomcat/conf/logging.properties
tomcat-server_1 | org.apache.catalina.startup.VersionLoggerListener.log Command line argument: -Djava.util.logging.manager=org.apache.juli.ClassLoaderLogManager
tomcat-server_1 | org.apache.catalina.startup.VersionLoggerListener.log Command line argument: -Djdk.tls.ephemeralDHKeySize=2048
tomcat-server_1 | org.apache.catalina.startup.VersionLoggerListener.log Command line argument: -Djava.protocol.handler.pkgs=org.apache.catalina.webresources
tomcat-server_1 | org.apache.catalina.startup.VersionLoggerListener.log Command line argument: -Dorg.apache.catalina.security.SecurityListener.UMASK=0027
tomcat-server_1 | org.apache.catalina.startup.VersionLoggerListener.log Command line argument: -Dignore.endorsed.dirs=
tomcat-server_1 | org.apache.catalina.startup.VersionLoggerListener.log Command line argument: -Dcatalina.base=/usr/local/tomcat
tomcat-server_1 | org.apache.catalina.startup.VersionLoggerListener.log Command line argument: -Dcatalina.home=/usr/local/tomcat
tomcat-server_1 | org.apache.catalina.startup.VersionLoggerListener.log Command line argument: -Djava.io.tmpdir=/usr/local/tomcat/temp
tomcat-server_1 | org.apache.catalina.core.AprLifecycleListener.lifecycleEvent Loaded Apache Tomcat Native library [1.2.27] using APR version [1.6.5].
tomcat-server_1 | org.apache.catalina.core.AprLifecycleListener.lifecycleEvent APR capabilities: IPv6 [true], sendfile [true], accept filters [false], random [true].
tomcat-server_1 | org.apache.catalina.core.AprLifecycleListener.lifecycleEvent APR/OpenSSL configuration: useAprConnector [false], useOpenSSL [true]
tomcat-server_1 | org.apache.catalina.core.AprLifecycleListener.initializeSSL OpenSSL successfully initialized [OpenSSL 1.1.1f 31 Mar 2020]
tomcat-server_1 | org.apache.coyote.AbstractProtocol.init Initializing ProtocolHandler ["http-nio-8080"]
tomcat-server_1 | org.apache.catalina.startup.Catalina.load Server initialization in [745] milliseconds
tomcat-server_1 | org.apache.catalina.core.StandardService.startInternal Starting service [Catalina]
tomcat-server_1 | org.apache.catalina.core.StandardEngine.startInternal Starting Servlet engine: [Apache Tomcat/9.0.45]
tomcat-server_1 | org.apache.catalina.startup.HostConfig.deployDirectory Deploying web application directory [/usr/local/tomcat/webapps/app.war]
tomcat-server_1 | org.apache.catalina.startup.HostConfig.deployDirectory Deployment of web application directory [/usr/local/tomcat/webapps/app.war] has finished in [361] ms
tomcat-server_1 | org.apache.coyote.AbstractProtocol.start Starting ProtocolHandler ["http-nio-8080"]
tomcat-server_1 | org.apache.catalina.startup.Catalina.start Server startup in [463] milliseconds
我尝试了一些东西,但没有成功。我是不是漏了什么?
谢谢你,
Atul
2条答案
按热度按时间zc0qhyus1#
我能解决这个问题。解决方案是创建一个单独的docker文件来创建一个tomcat镜像,并在docker composer文件中使用它。
问题是,即使是战争复制到tomcat的webapps文件夹,它也不会部署。请参阅日志以供参考:
由于镜像tomcat:9.0.45-jdk 11-adoptopenjdk-hotspot包含命令**'catalina.sh','run']**,docker-compose命令一执行,tomcat就启动了,在启动过程结束时,它将war文件复制到tomcat位置。所以它不会部署war文件。
这就是我发现的原因。(如果我错了,或者我错过了什么,请告诉我)。
所以最终的解决方案是这样的(这对我来说很有效):
创建docker文件。(例如- Dockerfile_web)
接下来是在docker-compose文件中添加此文件引用。
一旦我用docker-compose up运行它,它就开始工作了。
zfciruhq2#
我也遇到了同样的问题,war文件正在提取,但没有部署,docker日志中也没有错误或警告。在调试了两天之后,我改变了tomcat的docker镜像,它对我很有效。
以前我使用的是tomcat:9.0.80-jdk 17-corretto-al 2,在将其更改为tomcat:latest后,它开始正常工作。