version: "3" services: tomcat: image: "tomcat:latest" restart: always container_name: tomcat environment: - TZ=Asia/Shanghai ports: - 8888:8080 volumes: - ./conf/server.xml:/usr/local/tomcat/conf/server.xml - ./logs:/usr/local/tomcat/logs - ./webapps:/usr/local/tomcat/webapps
时间: 2024-02-14 11:07:16 浏览: 153
这个Docker Compose文件看起来很不错,您已经正确地将Tomcat容器映射到主机端口8888和本地的server.xml、logs和webapps目录。但是,您的server.xml配置文件可能有问题,因此Tomcat容器可能无法正常启动。您可以检查server.xml文件是否正确配置了Tomcat实例。以下是一个示例server.xml文件的示例配置:
```
<?xml version="1.0" encoding="UTF-8"?>
<Server port="8005" shutdown="SHUTDOWN">
<Listener className="org.apache.catalina.startup.VersionLoggerListener" />
<Listener className="org.apache.catalina.core.AprLifecycleListener" SSLEngine="on" />
<Listener className="org.apache.catalina.core.JasperListener" />
<Listener className="org.apache.catalina.core.JreMemoryLeakPreventionListener" />
<Listener className="org.apache.catalina.mbeans.GlobalResourcesLifecycleListener" />
<Listener className="org.apache.catalina.core.ThreadLocalLeakPreventionListener" />
<GlobalNamingResources>
<Resource name="UserDatabase" auth="Container"
type="org.apache.catalina.UserDatabase"
description="User database that can be updated and saved"
factory="org.apache.catalina.users.MemoryUserDatabaseFactory"
pathname="conf/tomcat-users.xml" />
</GlobalNamingResources>
<Service name="Catalina">
<Connector port="8080" protocol="HTTP/1.1"
connectionTimeout="20000"
redirectPort="8443" />
<Engine name="Catalina" defaultHost="localhost">
<Realm className="org.apache.catalina.realm.LockOutRealm">
<Realm className="org.apache.catalina.realm.UserDatabaseRealm"
resourceName="UserDatabase"/>
</Realm>
<Host name="localhost" appBase="webapps"
unpackWARs="true" autoDeploy="true">
<Valve className="org.apache.catalina.valves.AccessLogValve" directory="logs"
prefix="localhost_access_log" suffix=".txt"
pattern="%h %l %u %t "%r" %s %b" />
<Context path="" docBase="ROOT" debug="0" reloadable="true"/>
</Host>
</Engine>
</Service>
</Server>
```
如果您的server.xml文件类似于上面的示例,并且正确配置了Tomcat实例,那么您的Docker Compose文件应该能够正常工作了。
阅读全文