Search code examples
javalinuxdockertomcatgoogle-cloud-run

Google cloud run error "The user-provided container failed to start and listen on the port defined provided by the PORT=80 environment variable"


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?


Solution

  • 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.