我正在使用Docker进行一些测试,我有问题启动我的tomcat7容器,它有时会正确启动,有时不启动。这是几次尝试的例子
fred@fred-Latitude-E6520:~/docker/test2$ docker.io run tomcat7
* Starting Tomcat servlet engine tomcat7
...done.
May 04, 2014 5:31:19 PM org.apache.catalina.core.StandardService startInternal
INFO: Starting service Catalina
May 04, 2014 5:31:19 PM org.apache.catalina.core.StandardEngine startInternal
INFO: Starting Servlet Engine: Apache Tomcat/7.0.52 (Ubuntu)
May 04, 2014 5:31:19 PM org.apache.catalina.startup.HostConfig deployDirectory
INFO: Deploying web application directory /var/lib/tomcat7/webapps/ROOT
May 04, 2014 5:31:20 PM org.apache.coyote.AbstractProtocol start
INFO: Starting ProtocolHandler ["http-bio-8080"]
May 04, 2014 5:31:20 PM org.apache.catalina.startup.Catalina start
INFO: Server startup in 886 ms
fred@fred-Latitude-E6520:~/docker/test2$ docker.io run tomcat7
* Starting Tomcat servlet engine tomcat7
...fail!
fred@fred-Latitude-E6520:~/docker/test2$ docker.io run tomcat7
* Starting Tomcat servlet engine tomcat7
...fail!
fred@fred-Latitude-E6520:~/docker/test2$ docker.io run tomcat7
* Starting Tomcat servlet engine tomcat7
...done.
May 04, 2014 5:32:04 PM org.apache.catalina.core.StandardService startInternal
INFO: Starting service Catalina
May 04, 2014 5:32:04 PM org.apache.catalina.core.StandardEngine startInternal
INFO: Starting Servlet Engine: Apache Tomcat/7.0.52 (Ubuntu)
May 04, 2014 5:32:04 PM org.apache.catalina.startup.HostConfig deployDirectory
INFO: Deploying web application directory /var/lib/tomcat7/webapps/ROOT
May 04, 2014 5:32:05 PM org.apache.coyote.AbstractProtocol start
INFO: Starting ProtocolHandler ["http-bio-8080"]
May 04, 2014 5:32:05 PM org.apache.catalina.startup.Catalina start
INFO: Server startup in 833 ms
我的Dockerfile:
FROM ubuntu:14.04
# Update Ubuntu
RUN apt-get update && apt-get -y upgrade
# Add oracle java 7 repository
RUN apt-get -y install software-properties-common
RUN add-apt-repository ppa:webupd8team/java
RUN apt-get -y update
# Accept the Oracle Java license
RUN echo "oracle-java7-installer shared/accepted-oracle-license-v1-1 boolean true" | debconf-set-selections
# Install Oracle Java
RUN apt-get -y install oracle-java7-installer
# Install tomcat
RUN apt-get -y install tomcat7
RUN echo "JAVA_HOME=/usr/lib/jvm/java-7-oracle" >> /etc/default/tomcat7
EXPOSE 8080
# Start Tomcat, after starting Tomcat the container will stop. So use a 'trick' to keep it running.
CMD service tomcat7 start && tail -f /var/log/tomcat7/catalina.out
当它失败时,我怎么能看出出了什么问题?
Docker启动是否存在某种超时?如果我的容器没有在x秒内启动,那么Docker认为它是失败的?
答案 0 :(得分:1)
失败时:
docker logs $(docker -q -a -l)
这将告诉你失败的原因。
我认为问题可能是tomcat没有在前台运行所以你的docker容器结束了,你可能想尝试在supervisor下运行tomcat并放置:
CMD ["supervisord", "-n"]
作为你的命令。
这将告诉主管在前台运行它会为你运行tomcat。您可以通过快速谷歌找到很多tomcat主管示例confs。它应该很容易做到。
编辑:
或者,使用
在前台运行tomcattomcat/bin/catalina.sh run
并且应该具有相同的效果,因此您的cmd将如下所示:
CMD ["<path/to/tomcat>/bin/catalina.sh", "run"]
希望这会有所帮助