Hi!
I’m playing something with Tomcat. I would like to have conf directory as volume on Docker host. This is my docker-compose.yaml:
version: '3.3'
services:
tomcat:
image: tomcat:10.1.15-jdk17
container_name: tomcat
ports:
- '8084:8080'
volumes:
- ./tomcat/conf:/usr/local/tomcat/conf
- ./tomcat/webapps:/usr/local/tomcat/webapps
I also have directories created on host, for both volumes.
[root@archmedia docker-compose-tomcat]# tree
.
├── docker-compose.yaml
└── tomcat
├── conf
└── webapps
However, this wont work, container not starting, and this is everything what I can see from docker logs:
[root@archmedia docker-compose-tomcat]# docker logs tomcat
Nov 04, 2023 8:01:59 AM org.apache.catalina.startup.Catalina parseServerXml
WARNING: Unable to load server configuration from [/usr/local/tomcat/conf/server.xml]
java.io.FileNotFoundException: /usr/local/tomcat/conf/server.xml (No such file or directory)
at java.base/java.io.FileInputStream.open0(Native Method)
at java.base/java.io.FileInputStream.open(FileInputStream.java:216)
at java.base/java.io.FileInputStream.<init>(FileInputStream.java:157)
at java.base/java.io.FileInputStream.<init>(FileInputStream.java:111)
at java.base/sun.net.www.protocol.file.FileURLConnection.connect(FileURLConnection.java:86)
at java.base/sun.net.www.protocol.file.FileURLConnection.getInputStream(FileURLConnection.java:189)
at org.apache.catalina.startup.CatalinaBaseConfigurationSource.getResource(CatalinaBaseConfigurationSource.java:118)
at org.apache.tomcat.util.file.ConfigurationSource.getConfResource(ConfigurationSource.java:150)
at org.apache.tomcat.util.file.ConfigurationSource.getServerXml(ConfigurationSource.java:127)
at org.apache.catalina.startup.CatalinaBaseConfigurationSource.getServerXml(CatalinaBaseConfigurationSource.java:52)
at org.apache.catalina.startup.Catalina.parseServerXml(Catalina.java:631)
at org.apache.catalina.startup.Catalina.load(Catalina.java:732)
at org.apache.catalina.startup.Catalina.load(Catalina.java:769)
at java.base/jdk.internal.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
at java.base/jdk.internal.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:77)
at java.base/jdk.internal.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43)
at java.base/java.lang.reflect.Method.invoke(Method.java:568)
at org.apache.catalina.startup.Bootstrap.load(Bootstrap.java:307)
at org.apache.catalina.startup.Bootstrap.main(Bootstrap.java:477)
Nov 04, 2023 8:01:59 AM org.apache.catalina.startup.Catalina start
SEVERE: Cannot start server, server instance is not configured
From my understanding, at least this was the way I done before with all my containers, it is enough to create some empty directory on the host, then in docker-compose.yaml
define a volume as below, and all files from that location in container will be shown in host directory:
volumes:
- ./host/directory:/container/directory
Also, if I omit - ./tomcat/conf:/usr/local/tomcat/conf
in my docker-compose.yaml
, and using only - ./tomcat/webapps:/usr/local/tomcat/webapps
, everything is working as expected - container starts successfully, it is accessible on IP:PORT and all container files form /usr/local/tomcat/webapps
are presented on host inside ./tomcat/webapps
. E.g. like this:
version: '3.3'
services:
tomcat:
image: tomcat:10.1.15-jdk17
container_name: tomcat
ports:
- '8084:8080'
volumes:
- ./tomcat/webapps:/usr/local/tomcat/webapps
Does anybody know why conf
directory cannot be mounted as volume?
Thanks