最初的情况
在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
问题
服务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],2015 5:52:40 PM org.apache.catalina.startup.ClassLoaderFactory validateFile
WARNING: Problem with directory [/usr/share/tomcat7/server/classes],2015 5:52:40 PM org.apache.catalina.startup.ClassLoaderFactory validateFile
WARNING: Problem with directory [/usr/share/tomcat7/server],2015 5:52:40 PM org.apache.catalina.startup.ClassLoaderFactory validateFile
WARNING: Problem with directory [/usr/share/tomcat7/shared/classes],2015 5:52:40 PM org.apache.catalina.startup.ClassLoaderFactory validateFile
WARNING: Problem with directory [/usr/share/tomcat7/shared],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?
最佳答案
解决方案
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.由于服务启动,构建失败了,我不会从剧本中删除.我会进一步调查,但欢迎可能的解决方案.