1

I have build my application using the docker file on google gcp. I am trying to run my web application build/run on tomcat.

from ubuntu
COPY /mnt/opt/apache-tomcat-9.0.5/ /mnt/opt/apache-tomcat-9.0.5/
RUN apt update
COPY cronjob /etc/cron.d/cronjob
RUN chmod 0644 /etc/cron.d/cronjob
RUN crontab /etc/cron.d/cronjob
ENV CATALINA_HOME /mnt/opt/apache-tomcat-9.0.5
ENV PATH $CATALINA_HOME/bin:$PATH
ENV PATH /mnt/opt/java/jdk-10.0.1/bin:$PATH
ENV PORT 80
ENV HOST 0.0.0.0
EXPOSE 80 443
CMD /mnt/opt/apache-tomcat-9.0.5/bin/catalina.sh run
#ENTRYPOINT ["/mnt/opt/apache-tomcat-9.0.5/bin/catalina.sh", "run"]

Using the following approach to deploy on google cloud run.

docker tag miniimagesvideos gcr.io/serious-bearing-358305/miniimagesvideos
docker push gcr.io/serious-bearing-358305/miniimagesvideos
gcloud run deploy --image=gcr.io/serious-bearing-358305/miniimagesvideos --port=80 --region=asia-southeast2 --allow-unauthenticated platform=managed --command=/mnt/opt/apache-tomcat-9.0.5/bin/catalina.sh

I keep getting error mentioned in the subject line

  1. I looked at the logs and there is no additional information.
  2. As per the troubleshooting steps mentioned by Google document all the requirement seems to be ok. I am able to run my application successfully on Google cloud VM. The application is build on 64 bit.
  3. I have tried multiple options like using the --command, port, host parameter while trying to deploy.
  4. I have tried to use CMD, instead of ENTRYPOINT in dockerfile. However, the result remains the same. I have tried to invoke tomcat using startup.sh vs Catalina.sh. But the outcome remains the same.
  5. I have tried to deploy the application from GUI, but the same error comes up.

It seem container shuts down immediately while trying to deploy on Google Cloud run. Whereas, there is no issue while trying to run docker container on a Google VM. Is there any additional configuration required for Google cloud run. Why tomcat is not able to run on Google cloud run?

Shailender Jain
  • 25
  • 1
  • 14
  • Your deploy command specifies port 80 but the default for Catalina is 8000. https://github.com/apache/tomcat/blob/main/bin/catalina.sh – John Hanley May 15 '23 at 03:16
  • In my server.xml i have updated default port to 80. " . I am able to run the same on VM with PORT 80. – Shailender Jain May 15 '23 at 03:21
  • Have you tried enabling `firewall` as discussed [here](https://stackoverflow.com/a/45021525/18265570)? – Roopa M May 15 '23 at 06:31
  • The link discuss the issue with tomcat on VM. My question is related to Google cloud run which is expected to support docker container. On the referred link it seems root cause was tomcat taking too long to start. But, on my local VM tomcat is in start status in approx. 23 seconds. On google cloud run i have tried with the option to enable "Use HTTP/2 end-to-end". However, the result is same. Referring back to log details. I could see the following text "Tomcat started". It is then followed by "Container called exit(0)". There is nothing in the logs on why container crash. – Shailender Jain May 15 '23 at 07:19

2 Answers2

1

This could be due to bug in gcloud. It has been fixed in the latest release. Try updating to latest version by using below command

gcloud components update

If this still doesn’t work, You could use the following flag --format=export in the command gcloud run services describe --format=export <SERVICE-NAME> which would return the YAML file containing the configuration of the Cloud Run service. On this file you would have to change manually the fields “containerPort” and the “port” variable under “tcpSocket” in “startupProbe”.

Once you have the YAML properly configured you can use the following command to update the configuration of the service, effectively changing the port.

gcloud run services replace <yaml-file>

Roopa M
  • 2,171
  • 4
  • 12
  • I tried both the actions, but result is same. Please note there was no need to update "containerPort" and "port" variable under “tcpSocket” in “startupProbe” . The YAML.xml already had the value of 80. – Shailender Jain May 15 '23 at 08:43
  • have you tried to run the tomcat locally?By launching a docker container from docker file? If not can you try to launch container in local system with steps mentioned by you at point no 4(I have tried to use CMD, ins....)? – Badala Prashanth May 15 '23 at 11:44
  • Yes ...it is working on.my local system. I have tried with both ENTRYPOINT and CMD. It works. – Shailender Jain May 15 '23 at 14:59
  • I have modified the Dockerfile a little bit. https://codefile.io/f/eo5MchBAVx Put this file and apache-tomcat-9.0.75 in the same folder. I was able to deploy the image using cmd `gcloud run deploy`. Can you try to use `ENTRYPOINT` in the Dockerfile and deploy to a new service using the command `gcloud run deploy --image=IMAGE`? In case if you want to specify the entry point in the command it's fine but also need to set the argument [--args=run](https://cloud.google.com/run/docs/configuring/containers#configure-entrypoint) – Roopa M May 24 '23 at 07:11
  • @ShailenderJain We have to try to deploy to a new service since the current service might have cached some old configuration – Roopa M May 24 '23 at 07:19
0

The following combination worked on Google Cloud run.

 1. openjdk version "11.0.18"  
 2. apache-tomcat-10.1.8

Please note i was required to implement some additional steps for my app to migrate from 9.0.75 to 10.1.8. These are trivial changes to migrate from tomcat 9.x to 10.x.
SSL Connector needs an explicit tag for SSLHostconfig

    <SSLHostConfig hostName="test.test"
                       protocols="TLSv1.2">
            <Certificate certificateFile="/etc/letsencrypt/archive/miniimagesvideos.com/cert2.pem"                  certificateKeyFile="/etc/letsencrypt/archive/miniimagesvideos.com/privkey2.pem"              certificateChainFile="/etc/letsencrypt/archive/miniimagesvideos.com/chain2.pem" />
        </SSLHostConfig>
  </Connector>

In the context.xml the following needs to be added

<Loader jakartaConverter="TOMCAT" /> 

Conclusion After multiple troubleshooting, i could reach to the following conclusion

  1. Google cloud run execute Catalina.sh in a manner that the tomcat is running the background. Log indicate "Tomcat Started" and then there is another log of "container exited".

  2. However, for 10.X version tomcat is kicked off as a foreground process.

Shailender Jain
  • 25
  • 1
  • 14