gpt4 book ai didi

tomcat - 运行后 Docker Tomcat 退出 0

转载 作者:行者123 更新时间:2023-11-28 21:56:16 26 4
gpt4 key购买 nike

我从 Dockerfile 制作了一张图片:

FROM tomcat:8.0
COPY target/javahello.war /usr/local/tomcat/webapps/
EXPOSE 8080
CMD /usr/local/tomcat/bin/startup.sh

但在开始之后 - 它处于“退出”状态:

$ sudo docker run -ti 957a86defe4f
Using CATALINA_BASE: /usr/local/tomcat
Using CATALINA_HOME: /usr/local/tomcat
Using CATALINA_TMPDIR: /usr/local/tomcat/temp
Using JRE_HOME: /usr/lib/jvm/java-7-openjdk-amd64/jre
Using CLASSPATH: /usr/local/tomcat/bin/bootstrap.jar:/usr/local/tomcat/bin/tomcat-juli.jar
Tomcat started.

和:

$ sudo docker ps -a | head
CONTAINER ID IMAGE COMMAND CREATED STATUS PORTS NAMES
dc2309620baf 957a86defe4f:latest "/bin/sh -c /usr/loc 25 seconds ago Exited (0) 24 seconds ago insane_elion

logs 什么都不显示:

$ sudo docker logs dc2309620baf
Using CATALINA_BASE: /usr/local/tomcat
Using CATALINA_HOME: /usr/local/tomcat
Using CATALINA_TMPDIR: /usr/local/tomcat/temp
Using JRE_HOME: /usr/lib/jvm/java-7-openjdk-amd64/jre
Using CLASSPATH: /usr/local/tomcat/bin/bootstrap.jar:/usr/local/tomcat/bin/tomcat-juli.jar
Tomcat started.

如果我直接从容器运行 startup.sh - Tomcat 按预期工作:

$ sudo docker run -ti 957a86defe4f bash
root@b00b541e6ccb:/usr/local/tomcat# ./bin/startup.sh
Using CATALINA_BASE: /usr/local/tomcat
Using CATALINA_HOME: /usr/local/tomcat
Using CATALINA_TMPDIR: /usr/local/tomcat/temp
Using JRE_HOME: /usr/lib/jvm/java-7-openjdk-amd64/jre
Using CLASSPATH: /usr/local/tomcat/bin/bootstrap.jar:/usr/local/tomcat/bin/tomcat-juli.jar
Tomcat started.
# ps -axu | grep tomcat
root 15 44.7 1.1 6258648 193484 ? Sl 14:54 0:04 /usr/lib/jvm/java-7-openjdk-amd64/jre/bin/java -Djava.util.logging.config.file=/usr/local/tomcat/conf/logging.properties -Djava.util.logging.manager=org.apache.juli.ClassLoaderLogManager -Djdk.tls.ephemeralDHKeySize=2048 -Djava.protocol.handler.pkgs=org.apache.catalina.webresources -Djava.endorsed.dirs=/usr/local/tomcat/endorsed -classpath /usr/local/tomcat/bin/bootstrap.jar:/usr/local/tomcat/bin/tomcat-juli.jar -Dcatalina.base=/usr/local/tomcat -Dcatalina.home=/usr/local/tomcat -Djava.io.tmpdir=/usr/local/tomcat/temp org.apache.catalina.startup.Bootstrap start

是不是我的CMD有问题?

最佳答案

带有 startup.sh 的 tomcat 将在后台启动 tomcat(作为服务)并且 docker 将以 code 0 退出,这是正常和预期的行为。

在这种情况下,您需要使用 catalina.sh run 将 tomcat 作为前台进程启动。

 FROM tomcat:8.0
COPY target/javahello.war /usr/local/tomcat/webapps/
EXPOSE 8080
CMD /usr/local/tomcat/bin/catalina.sh run

当您在容器内运行 startup.sh 时,它可以正常工作,因为您在“bash”(您的前台进程)中。

关于tomcat - 运行后 Docker Tomcat 退出 0,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/40157992/

26 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com