2

I have built a tomcat docker image from here.

I want to map the tomcat folder to the host machine, so I can simply access it, mainly I will need webapps and logs folder. webapps folder is simply required to deploy a war file and logs folder is for log tracing from host machine.

So I make it simpler, by mapping the whole tomcat folder like below:

docker run -ti --rm -p 8888:8080 -v C:/data:/usr/local/tomcat/ <image>

But I got this error:

docker: Error response from daemon: OCI runtime create failed: container_linux.go:296: starting container process caused "exec: \"catalina.sh\": executable file not found in $PATH": unknown.

Any suggestions?

Sam YC
  • 10,725
  • 19
  • 102
  • 158

2 Answers2

3

In the tomcat docker file you linked, line 3:

ENV CATALINA_HOME /usr/local/tomcat

Which means, when you mount your C:\data to /usr/local/tomcat/, you're removing pretty much all of the files tomcat needs in order to function, including the catalina.sh being complained about. Docker bind mounted volumes are not additive, so when you mount C:\data to /usr/local/tomcat/, you are totally replacing what exists in /usr/local/tomcat with what is in C:\data.

To do what you want here, consider changing the default locations where tomcat will look for webapps and logging. Here's a helpful SO answer to get you going in the right direction.

Then you'd do something like this:

docker run -ti --rm -p 8888:8080 -v C:/data/webapps:/webapps -v C:/data/logs:/logs <image>

bluescores
  • 4,437
  • 1
  • 20
  • 34
  • 2
    ok, I got it work by this: `docker run -ti --rm -p 8888:8080 -v C:/data/webapps:/usr/local/tomcat/webapps -v C:/data/logs:/usr/local/tomcat/logs ` – Sam YC Mar 12 '18 at 02:29
0

As specified in the Dockerfile, the container is started using the command CMD ["catalina.sh", "run"] which is found under /usr/local/tomcat.

When you mount an existing directory from the host onto /usr/local/tomcat, the content inside the container on /usr/local/tomcat will be the same as the host dir. This is causing the startup script catalina.sh to not be found.

To solve this problem, you can specify a non existing directory on the host, which will be created.

docker run --rm -p 8888:8080 -v C:/data/tomcat:/usr/local/tomcat/ <image>

where C:/data/tomcat doesn't exist or use a named volume with a specific mount point as such:

docker volume create --name tomcat-data -o type=none -o device=C:/data/tomcat -o o=bind

docker run -ti --rm -p 8888:8080 -v tomcat-data:/usr/local/tomcat/ <image>
yamenk
  • 46,736
  • 10
  • 93
  • 87
  • hi yamenk, this doesn't work, I use your command and make sure `C:/data/tomcat` doesn't exist, after issue command, `C:/data/tomcat` is created but empty and got the same error messages. – Sam YC Mar 12 '18 at 02:22