我用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
是否有问题?
答案 0 :(得分:3)
带有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
”(您的前台进程)。