Home > Blockchain >  Dockerfile with Tomcat catalina.sh run does not run
Dockerfile with Tomcat catalina.sh run does not run

Time:08-10

I can build the Dockerfile. When I do docker run -it path-to-image/tomcat9:latest and check the logs, there isn't a catalina.out and the run fail with getting /bin/sh: ["catalina.sh",: command not found.

Here is my Dockerfile

FROM gitlab-registry.gs.mil/gets-development/docker/openjdk11

USER root

# Copy Tomcat and start
ADD imageFiles/apache-tomcat-9.0.65.tar.gz /usr/local/
RUN mv /usr/local/apache-tomcat-9.0.65/ /usr/local/tomcat

ENV WORKPATH /usr/local
WORKDIR $WORKPATH

ENV CATALINA_HOME /usr/local/tomcat
ENV CATALINA_BASE /usr/local/tomcat

ENV PATH $PATH:$CATALINA_HOME/bin:$CATALINA_HOME/lib

EXPOSE 8080
CMD ["/usr/local/tomcat/bin/catalina.sh", "run"]

Build command:

docker build -t gitlab-registry.gs.mil/gets-development/docker/tomcat9-test .

Start command:

docker run --name tomcatTest -it gitlab-registry.gs.mil/gets-development/docker/tomcat9-test:latest /bin/bash

Trying to connect inside the docker container to the localhost fails

curl: (7) Failed to connect to localhost port 8080: Connection refused

There are no log files

[root@b058163e9605 local]# cd tomcat/logs/
[root@b058163e9605 logs]# ls -als
total 0
0 drwxr-x--- 2 root root   6 Jul 14 12:28 .
0 drwxr-xr-x 9 root root 220 Aug  5 16:17 ..
[root@b058163e9605 logs]# 

This is telling me that Tomcat did not start. Starting Tomcat inside the container, tomcat could launch success:

[root@b058163e9605 bin]# ./catalina.sh run
.....
08-Aug-2022 13:12:02.934 INFO [main] org.apache.coyote.AbstractProtocol.init Initializing ProtocolHandler ["http-nio-8080"]
08-Aug-2022 13:12:03.038 INFO [main] org.apache.catalina.startup.Catalina.load Server initialization in [1590] milliseconds
08-Aug-2022 13:12:03.204 INFO [main] org.apache.catalina.core.StandardService.startInternal Starting service [Catalina]
08-Aug-2022 13:12:03.205 INFO [main] org.apache.catalina.core.StandardEngine.startInternal Starting Servlet engine: [Apache Tomcat/9.0.65]
08-Aug-2022 13:12:03.224 INFO [main] org.apache.catalina.startup.HostConfig.deployDirectory Deploying web application directory [/usr/local/tomcat/webapps/ROOT]
08-Aug-2022 13:12:03.877 INFO [main] org.apache.catalina.startup.HostConfig.deployDirectory Deployment of web application directory [/usr/local/tomcat/webapps/ROOT] has finished in [652] ms
08-Aug-2022 13:12:03.879 INFO [main] org.apache.catalina.startup.HostConfig.deployDirectory Deploying web application directory [/usr/local/tomcat/webapps/docs]
08-Aug-2022 13:12:03.945 INFO [main] org.apache.catalina.startup.HostConfig.deployDirectory Deployment of web application directory [/usr/local/tomcat/webapps/docs] has finished in [66] ms
08-Aug-2022 13:12:03.947 INFO [main] org.apache.catalina.startup.HostConfig.deployDirectory Deploying web application directory [/usr/local/tomcat/webapps/examples]
08-Aug-2022 13:12:04.559 INFO [main] org.apache.catalina.startup.HostConfig.deployDirectory Deployment of web application directory [/usr/local/tomcat/webapps/examples] has finished in [613] ms
08-Aug-2022 13:12:04.562 INFO [main] org.apache.catalina.startup.HostConfig.deployDirectory Deploying web application directory [/usr/local/tomcat/webapps/host-manager]
08-Aug-2022 13:12:04.626 INFO [main] org.apache.catalina.startup.HostConfig.deployDirectory Deployment of web application directory [/usr/local/tomcat/webapps/host-manager] has finished in [63] ms
08-Aug-2022 13:12:04.626 INFO [main] org.apache.catalina.startup.HostConfig.deployDirectory Deploying web application directory [/usr/local/tomcat/webapps/manager]
08-Aug-2022 13:12:04.717 INFO [main] org.apache.catalina.startup.HostConfig.deployDirectory Deployment of web application directory [/usr/local/tomcat/webapps/manager] has finished in [90] ms
08-Aug-2022 13:12:04.733 INFO [main] org.apache.coyote.AbstractProtocol.start Starting ProtocolHandler ["http-nio-8080"]
08-Aug-2022 13:12:04.767 INFO [main] org.apache.catalina.startup.Catalina.start Server startup in [1728] milliseconds

Last, I check the Docker logs shows me what I did inside the container, but no other information.

Please assist.

CodePudding user response:

Your docker run command does not launch Tomcat but simply bash. Notice the last argument

docker run --name tomcatTest -it gitlab-registry.gs.mil/gets-development/docker/tomcat9-test:latest /bin/bash

change it into

docker run --name tomcatTest gitlab-registry.gs.mil/gets-development/docker/tomcat9-test:latest

If you want a shell to investigate what is going on inside a running container, use

docker exec -it tomcatTest /bin/bash
  • Related