tomcat7无法在Ubuntu Docker容器内启动

时间:2015-04-16 18:35:03

标签: tomcat ubuntu tomcat7 docker

最初的情况

在Ubuntu(14.04 / 14.10)中,运行以下命令:

apt-get update && apt-get install tomcat7
service tomcat7 start

一方面,我按照预期在VirtualBox VM和tomcat7 startet中尝试了这个:

vagrant init hashicorp/precise32
vagrant up

另一方面,我在Docker容器中尝试了这个,如下所示启动:

sudo docker run -it --name tomcattest ubuntu bash

问题

service tomcat7 start 命令输出[fail]。然而,tomcat正在运行,但 /var/log/tomcat7/catalina.out 表示如下:

Apr 16, 2015 5:52:40 PM org.apache.catalina.startup.ClassLoaderFactory validateFile
WARNING: Problem with directory [/usr/share/tomcat7/common/classes], exists: [false], isDirectory: [false], canRead: [false]
Apr 16, 2015 5:52:40 PM org.apache.catalina.startup.ClassLoaderFactory validateFile
WARNING: Problem with directory [/usr/share/tomcat7/common], exists: [false], isDirectory: [false], canRead: [false]
Apr 16, 2015 5:52:40 PM org.apache.catalina.startup.ClassLoaderFactory validateFile
WARNING: Problem with directory [/usr/share/tomcat7/server/classes], exists: [false], isDirectory: [false], canRead: [false]
Apr 16, 2015 5:52:40 PM org.apache.catalina.startup.ClassLoaderFactory validateFile
WARNING: Problem with directory [/usr/share/tomcat7/server], exists: [false], isDirectory: [false], canRead: [false]
Apr 16, 2015 5:52:40 PM org.apache.catalina.startup.ClassLoaderFactory validateFile
WARNING: Problem with directory [/usr/share/tomcat7/shared/classes], exists: [false], isDirectory: [false], canRead: [false]
Apr 16, 2015 5:52:40 PM org.apache.catalina.startup.ClassLoaderFactory validateFile
WARNING: Problem with directory [/usr/share/tomcat7/shared], exists: [false], isDirectory: [false], canRead: [false]
Apr 16, 2015 5:52:40 PM org.apache.coyote.AbstractProtocol init
INFO: Initializing ProtocolHandler ["http-bio-8080"]
Apr 16, 2015 5:52:40 PM org.apache.catalina.startup.Catalina load
INFO: Initialization processed in 514 ms
Apr 16, 2015 5:52:41 PM org.apache.catalina.core.StandardService startInternal
INFO: Starting service Catalina
Apr 16, 2015 5:52:41 PM org.apache.catalina.core.StandardEngine startInternal
INFO: Starting Servlet Engine: Apache Tomcat/7.0.52 (Ubuntu)
Apr 16, 2015 5:52:41 PM org.apache.catalina.startup.HostConfig deployDirectory
INFO: Deploying web application directory /var/lib/tomcat7/webapps/ROOT
Apr 16, 2015 5:52:42 PM org.apache.coyote.AbstractProtocol start
INFO: Starting ProtocolHandler ["http-bio-8080"]
Apr 16, 2015 5:52:42 PM org.apache.catalina.startup.Catalina start
INFO: Server startup in 1150 ms

搜索解释

有没有人可以解释不同的行为并告诉我是否有可能通过apt-get在没有警告的情况下通过apt-get安装tomcat7?

2 个答案:

答案 0 :(得分:15)

解决方案

tomcat启动脚本需要一些特殊权限。具体它需要检查所有正在运行的进程,以验证自己是否正在运行。您可以为Docker容器提供以下权限,以使tomcat启动脚本成功退出:

sudo docker run --cap-add SYS_PTRACE -it ubuntu bash

重要的选项是 - cap-add SYS_PTRACE ,所有其他选项可能会有所不同。在docker github上讨论这个问题至少有一个问题:

https://github.com/docker/docker/issues/6800

后续问题

尽管如此,我发现无法为图像的docker构建设置此权限。我的最终目标是运行一个在其中执行Ansible playbook的docker build。由于服务启动,构建失败了,我不会从剧本中删除。我会进一步调查,但欢迎可能的解决方案。

答案 1 :(得分:1)

This article报告相同的错误(对于Tomcat8,但它也应该适用于Tomcat7):

  

我不知道为什么,但似乎Ubuntu上的Tomcat 8没有以任何有意义的方式配置。一切都可用,但我们需要一些符号链接,以及创建临时目录。这转换为Dockerfile中的以下指令:

RUN ln -s /var/lib/tomcat8/common $CATALINA_HOME/common && \\
    ln -s /var/lib/tomcat8/server $CATALINA_HOME/server && \\
    ln -s /var/lib/tomcat8/shared $CATALINA_HOME/shared && \\
    ln -s /etc/tomcat8 $CATALINA_HOME/conf && \\
    mkdir $CATALINA_HOME/temp

但实际原因可能是this question

  

CATALINA_BASE等。只能在/etc/init.d/tomcat8中设置   在docker镜像中,该服务不会像在完整VM中那样进行初始化。