我正在尝试在tomcat docker容器上部署战争。 默认情况下,在列出的http端口上可以访问Tomcat管理器。 我不要这种行为。为避免这种情况,我进行了https://stackoverflow.com/a/7706950/3143009所述的ROOT.xml上下文文件。
ROOT.xml通过docker卷共享,并包含上下文定义:
<Context docBase="/usr/tomcat/custom-webapp/app.war" reloadable="true" />
在我看来,所有事情都是正确的,但是当我尝试启动tomcat容器时,发生FileNotFindException,告诉/ tomcat未找到/usr/tomcat/custom-webapp/app.war(/ usr / tomcat / custom-webapp也是包含app.war文件的共享卷。
我的docker-compose文件:
version : '3'
tomcat:
image: tomcat:9.0.27-jdk8-openjdk
hostname: tomcat
restart: on-failure
ports:
- 10000:8080
volumes:
- ./data/logs/:/usr/local/tomcat/logs/
- ./data/context-ROOT.xml:/usr/local/tomcat/conf/Catalina/localhost/ROOT.xml
- ./data/custom-webapp:/usr/local/tomcat/custom-webapp
我确定app.war文件已安装在容器中。当我进入容器或执行docker-compose run tomcat ls /usr/local/tomcat/custom-webapp
时,可以看到它。但是在启动时,tomcat似乎找不到该文件。这对我来说很奇怪。
有人知道为什么tomcat容器无法访问app.war文件吗?
在错误堆栈跟踪下方。
> tomcat_1 | 25-Oct-2019 14:43:55.287 INFO [main]
> org.apache.catalina.startup.HostConfig.deployDescriptor Deploying
> deployment descriptor
> [/usr/local/tomcat/conf/Catalina/localhost/ROOT.xml] tomcat_1 |
> 25-Oct-2019 14:43:55.307 WARNING [main]
> org.apache.catalina.startup.HostConfig.deployDescriptor Deployment of
> deployment descriptor
> [/usr/local/tomcat/conf/Catalina/localhost/ROOT.xml] with an external
> docBase means the directory [/usr/local/tomcat/webapps/ROOT] in the
> appBase will be ignored tomcat_1 | 25-Oct-2019 14:43:55.331 SEVERE
> [main] org.apache.catalina.startup.ContextConfig.beforeStart Exception
> fixing docBase for context [] tomcat_1 |
> java.io.FileNotFoundException: /usr/tomcat/custom-webapp/mytower.war
> (No such file or directory) tomcat_1 | at
> java.io.FileInputStream.open0(Native Method) tomcat_1 |
> at java.io.FileInputStream.open(FileInputStream.java:195) tomcat_1
> | at
> java.io.FileInputStream.<init>(FileInputStream.java:138) tomcat_1 |
> at java.io.FileInputStream.<init>(FileInputStream.java:93) tomcat_1
> | at
> sun.net.www.protocol.file.FileURLConnection.connect(FileURLConnection.java:90)
> tomcat_1 | at
> sun.net.www.protocol.file.FileURLConnection.getInputStream(FileURLConnection.java:188)
> tomcat_1 | at
> org.apache.catalina.startup.ExpandWar.expand(ExpandWar.java:90)
> tomcat_1 | at
> org.apache.catalina.startup.ContextConfig.fixDocBase(ContextConfig.java:615)
> tomcat_1 | at
> org.apache.catalina.startup.ContextConfig.beforeStart(ContextConfig.java:747)
> tomcat_1 | at
> org.apache.catalina.startup.ContextConfig.lifecycleEvent(ContextConfig.java:303)
> tomcat_1 | at
> org.apache.catalina.util.LifecycleBase.fireLifecycleEvent(LifecycleBase.java:123)
> tomcat_1 | at
> org.apache.catalina.util.LifecycleBase.setStateInternal(LifecycleBase.java:423)
> tomcat_1 | at
> org.apache.catalina.util.LifecycleBase.start(LifecycleBase.java:182)
> tomcat_1 | at
> org.apache.catalina.core.ContainerBase.addChildInternal(ContainerBase.java:717)
> tomcat_1 | at
> org.apache.catalina.core.ContainerBase.addChild(ContainerBase.java:690)
> tomcat_1 | at
> org.apache.catalina.core.StandardHost.addChild(StandardHost.java:705)
> tomcat_1 | at
> org.apache.catalina.startup.HostConfig.deployDescriptor(HostConfig.java:631)
> tomcat_1 | at
> org.apache.catalina.startup.HostConfig$DeployDescriptor.run(HostConfig.java:1831)
> tomcat_1 | at
> java.util.concurrent.Executors$RunnableAdapter.call(Executors.java:511)
> tomcat_1 | at
> java.util.concurrent.FutureTask.run(FutureTask.java:266) tomcat_1 |
> at
> org.apache.tomcat.util.threads.InlineExecutorService.execute(InlineExecutorService.java:75)
> tomcat_1 | at
> java.util.concurrent.AbstractExecutorService.submit(AbstractExecutorService.java:112)
> tomcat_1 | at
> org.apache.catalina.startup.HostConfig.deployDescriptors(HostConfig.java:526)
> tomcat_1 | at
> org.apache.catalina.startup.HostConfig.deployApps(HostConfig.java:425)
> tomcat_1 | at
> org.apache.catalina.startup.HostConfig.start(HostConfig.java:1576)
> tomcat_1 | at
> org.apache.catalina.startup.HostConfig.lifecycleEvent(HostConfig.java:309)
> tomcat_1 | at
> org.apache.catalina.util.LifecycleBase.fireLifecycleEvent(LifecycleBase.java:123)
> tomcat_1 | at
> org.apache.catalina.util.LifecycleBase.setStateInternal(LifecycleBase.java:423)
> tomcat_1 | at
> org.apache.catalina.util.LifecycleBase.setState(LifecycleBase.java:366)
> tomcat_1 | at
> org.apache.catalina.core.ContainerBase.startInternal(ContainerBase.java:936)
> tomcat_1 | at
> org.apache.catalina.core.StandardHost.startInternal(StandardHost.java:841)
> tomcat_1 | at
> org.apache.catalina.util.LifecycleBase.start(LifecycleBase.java:183)
> tomcat_1 | at
> org.apache.catalina.core.ContainerBase$StartChild.call(ContainerBase.java:1384)
> tomcat_1 | at
> org.apache.catalina.core.ContainerBase$StartChild.call(ContainerBase.java:1374)
> tomcat_1 | at
> java.util.concurrent.FutureTask.run(FutureTask.java:266) tomcat_1 |
> at
> org.apache.tomcat.util.threads.InlineExecutorService.execute(InlineExecutorService.java:75)
> tomcat_1 | at
> java.util.concurrent.AbstractExecutorService.submit(AbstractExecutorService.java:134)
> tomcat_1 | at
> org.apache.catalina.core.ContainerBase.startInternal(ContainerBase.java:909)
> tomcat_1 | at
> org.apache.catalina.core.StandardEngine.startInternal(StandardEngine.java:262)
> tomcat_1 | at
> org.apache.catalina.util.LifecycleBase.start(LifecycleBase.java:183)
> tomcat_1 | at
> org.apache.catalina.core.StandardService.startInternal(StandardService.java:421)
> tomcat_1 | at
> org.apache.catalina.util.LifecycleBase.start(LifecycleBase.java:183)
> tomcat_1 | at
> org.apache.catalina.core.StandardServer.startInternal(StandardServer.java:930)
> tomcat_1 | at
> org.apache.catalina.util.LifecycleBase.start(LifecycleBase.java:183)
> tomcat_1 | at
> org.apache.catalina.startup.Catalina.start(Catalina.java:633) tomcat_1
> | at sun.reflect.NativeMethodAccessorImpl.invoke0(Native
> Method) tomcat_1 | at
> sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:62)
> tomcat_1 | at
> sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43)
> tomcat_1 | at
> java.lang.reflect.Method.invoke(Method.java:498) tomcat_1 |
> at org.apache.catalina.startup.Bootstrap.start(Bootstrap.java:344)
> tomcat_1 | at
> org.apache.catalina.startup.Bootstrap.main(Bootstrap.java:475)
> tomcat_1 | 25-Oct-2019 14:43:56.054 SEVERE [main]
> org.apache.catalina.startup.HostConfig.deployDescriptor Error
> deploying deployment descriptor
> [/usr/local/tomcat/conf/Catalina/localhost/ROOT.xml] tomcat_1 |
> java.lang.IllegalStateException: Error starting child tomcat_1 |
> at
> org.apache.catalina.core.ContainerBase.addChildInternal(ContainerBase.java:720)
> tomcat_1 | at
> org.apache.catalina.core.ContainerBase.addChild(ContainerBase.java:690)
> tomcat_1 | at
> org.apache.catalina.core.StandardHost.addChild(StandardHost.java:705)
> tomcat_1 | at
> org.apache.catalina.startup.HostConfig.deployDescriptor(HostConfig.java:631)
> tomcat_1 | at
> org.apache.catalina.startup.HostConfig$DeployDescriptor.run(HostConfig.java:1831)
> tomcat_1 | at
> java.util.concurrent.Executors$RunnableAdapter.call(Executors.java:511)
> tomcat_1 | at
> java.util.concurrent.FutureTask.run(FutureTask.java:266) tomcat_1 |
> at
> org.apache.tomcat.util.threads.InlineExecutorService.execute(InlineExecutorService.java:75)
> tomcat_1 | at
> java.util.concurrent.AbstractExecutorService.submit(AbstractExecutorService.java:112)
> tomcat_1 | at
> org.apache.catalina.startup.HostConfig.deployDescriptors(HostConfig.java:526)
> tomcat_1 | at
> org.apache.catalina.startup.HostConfig.deployApps(HostConfig.java:425)
> tomcat_1 | at
> org.apache.catalina.startup.HostConfig.start(HostConfig.java:1576)
> tomcat_1 | at
> org.apache.catalina.startup.HostConfig.lifecycleEvent(HostConfig.java:309)
> tomcat_1 | at
> org.apache.catalina.util.LifecycleBase.fireLifecycleEvent(LifecycleBase.java:123)
> tomcat_1 | at
> org.apache.catalina.util.LifecycleBase.setStateInternal(LifecycleBase.java:423)
> tomcat_1 | at
> org.apache.catalina.util.LifecycleBase.setState(LifecycleBase.java:366)
> tomcat_1 | at
> org.apache.catalina.core.ContainerBase.startInternal(ContainerBase.java:936)
> tomcat_1 | at
> org.apache.catalina.core.StandardHost.startInternal(StandardHost.java:841)
> tomcat_1 | at
> org.apache.catalina.util.LifecycleBase.start(LifecycleBase.java:183)
> tomcat_1 | at
> org.apache.catalina.core.ContainerBase$StartChild.call(ContainerBase.java:1384)
> tomcat_1 | at
> org.apache.catalina.core.ContainerBase$StartChild.call(ContainerBase.java:1374)
> tomcat_1 | at
> java.util.concurrent.FutureTask.run(FutureTask.java:266) tomcat_1 |
> at
> org.apache.tomcat.util.threads.InlineExecutorService.execute(InlineExecutorService.java:75)
> tomcat_1 | at
> java.util.concurrent.AbstractExecutorService.submit(AbstractExecutorService.java:134)
> tomcat_1 | at
> org.apache.catalina.core.ContainerBase.startInternal(ContainerBase.java:909)
> tomcat_1 | at
> org.apache.catalina.core.StandardEngine.startInternal(StandardEngine.java:262)
> tomcat_1 | at
> org.apache.catalina.util.LifecycleBase.start(LifecycleBase.java:183)
> tomcat_1 | at
> org.apache.catalina.core.StandardService.startInternal(StandardService.java:421)
> tomcat_1 | at
> org.apache.catalina.util.LifecycleBase.start(LifecycleBase.java:183)
> tomcat_1 | at
> org.apache.catalina.core.StandardServer.startInternal(StandardServer.java:930)
> tomcat_1 | at
> org.apache.catalina.util.LifecycleBase.start(LifecycleBase.java:183)
> tomcat_1 | at
> org.apache.catalina.startup.Catalina.start(Catalina.java:633) tomcat_1
> | at sun.reflect.NativeMethodAccessorImpl.invoke0(Native
> Method) tomcat_1 | at
> sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:62)
> tomcat_1 | at
> sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43)
> tomcat_1 | at
> java.lang.reflect.Method.invoke(Method.java:498) tomcat_1 |
> at org.apache.catalina.startup.Bootstrap.start(Bootstrap.java:344)
> tomcat_1 | at
> org.apache.catalina.startup.Bootstrap.main(Bootstrap.java:475)
> tomcat_1 | Caused by: org.apache.catalina.LifecycleException:
> Failed to start component
> [org.apache.catalina.webresources.StandardRoot@2a556333] tomcat_1 |
> at
> org.apache.catalina.util.LifecycleBase.handleSubClassException(LifecycleBase.java:440)
> tomcat_1 | at
> org.apache.catalina.util.LifecycleBase.start(LifecycleBase.java:198)
> tomcat_1 | at
> org.apache.catalina.core.StandardContext.resourcesStart(StandardContext.java:4800)
> tomcat_1 | at
> org.apache.catalina.core.StandardContext.startInternal(StandardContext.java:4935)
> tomcat_1 | at
> org.apache.catalina.util.LifecycleBase.start(LifecycleBase.java:183)
> tomcat_1 | at
> org.apache.catalina.core.ContainerBase.addChildInternal(ContainerBase.java:717)
> tomcat_1 | ... 37 more tomcat_1 | Caused by:
> java.lang.IllegalArgumentException: The main resource set specified
> [/usr/tomcat/custom-webapp/mytower.war] is not valid tomcat_1 |
> at
> org.apache.catalina.webresources.StandardRoot.createMainResourceSet(StandardRoot.java:752)
> tomcat_1 | at
> org.apache.catalina.webresources.StandardRoot.startInternal(StandardRoot.java:709)
> tomcat_1 | at org.apache
答案 0 :(得分:0)
您没有使用卷,而是使用bind-mounts
。这意味着本地主机路径已安装到容器中,./data/custom-webapp
的内容将替换/usr/local/tomcat/custom-webapp
目录的内容。
因此,您的ROOT.xml
应该如下所示:
<Context docBase="/usr/local/tomcat/custom-webapp/app.war" reloadable="true" />
和app.war
应该在主机的./data/custom-webapp
目录中。