2016-10-20 204 views
1

後退出0我從Dockerfile製成的圖像:泊塢窗Tomcat的運行

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 
[email protected]:/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

回答

2

startup.sh的tomcat將在後臺啓動tomcat(作爲服務),並且docker將以code 0退出,這是正常和預期的行爲。

在這種情況下,您需要啓動tomcat作爲前臺進程catalina.sh run

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」(你的前臺進程)。