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

huangapple go评论53阅读模式
英文:

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 built my application using the Docker file on Google GCP. I am trying to run my web application build/run on Tomcat.

from Ubuntu <br>
COPY /mnt/opt/apache-tomcat-9.0.5/ /mnt/opt/apache-tomcat-9.0.5/ <br>
RUN apt update <br>
COPY cronjob /etc/cron.d/cronjob <br>
RUN chmod 0644 /etc/cron.d/cronjob <br>
RUN crontab /etc/cron.d/cronjob <br>
ENV CATALINA_HOME /mnt/opt/apache-tomcat-9.0.5 <br>
ENV PATH $CATALINA_HOME/bin:$PATH <br>
ENV PATH /mnt/opt/java/jdk-10.0.1/bin:$PATH <br>
ENV PORT 80 <br>
ENV HOST 0.0.0.0 <br>
EXPOSE 80 443 <br>
CMD /mnt/opt/apache-tomcat-9.0.5/bin/catalina.sh run <br>
#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 <br> docker push gcr.io/serious-bearing-358305/miniimagesvideos <br> 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 an 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 requirements seem to be ok. I am able to run my application successfully on Google Cloud VM. The application is built 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 the 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 seems the container shuts down immediately while trying to deploy on Google Cloud Run. Whereas, there is no issue while trying to run a 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?

英文:

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 <br>
COPY /mnt/opt/apache-tomcat-9.0.5/ /mnt/opt/apache-tomcat-9.0.5/ <br>
RUN apt update <br>
COPY cronjob /etc/cron.d/cronjob <br>
RUN chmod 0644 /etc/cron.d/cronjob <br>
RUN crontab /etc/cron.d/cronjob <br>
ENV CATALINA_HOME /mnt/opt/apache-tomcat-9.0.5 <br>
ENV PATH $CATALINA_HOME/bin:$PATH <br>
ENV PATH /mnt/opt/java/jdk-10.0.1/bin:$PATH <br>
ENV PORT 80 <br>
ENV HOST 0.0.0.0 <br>
EXPOSE 80 443 <br>
CMD /mnt/opt/apache-tomcat-9.0.5/bin/catalina.sh run <br>
#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 <br> docker push gcr.io/serious-bearing-358305/miniimagesvideos <br> 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?

答案1

得分: 1

这可能是由于gcloud中的错误导致的。已经在最新版本中修复了它。尝试使用以下命令更新到最新版本

gcloud components update

如果这仍然不起作用,您可以在gcloud run services describe --format=export <SERVICE-NAME>命令中使用以下标志--format=export,它将返回包含Cloud Run服务配置的YAML文件。在此文件中,您需要手动更改“startupProbe”下的“containerPort”和“tcpSocket”中的“port”变量字段。

一旦您正确配置了YAML,您可以使用以下命令来更新服务的配置,从而更改端口。

gcloud run services replace <yaml-file>

英文:

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 &lt;SERVICE-NAME&gt;
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 &lt;yaml-file&gt;

答案2

得分: 0

以下组合在Google Cloud run上有效。

  1. openjdk版本 "11.0.18"
  2. apache-tomcat-10.1.8

请注意,我需要实施一些额外的步骤,以使我的应用从9.0.75迁移到10.1.8。这些是从Tomcat 9.x迁移到10.x的微不足道的更改。
SSL连接器需要为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>

在context.xml中需要添加以下内容

<Loader jakartaConverter="TOMCAT" />

结论
经过多次故障排除,我得出以下结论:

  1. Google Cloud Run以一种使Tomcat在后台运行的方式执行Catalina.sh。日志显示"Tomcat Started",然后有另一个日志"container exited"。

  2. 然而,对于10.X版本,Tomcat作为前台进程启动。

英文:

The following combination worked on Google Cloud run.

 1. openjdk version &quot;11.0.18&quot;  
 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. <br>
SSL Connector needs an explicit tag for SSLHostconfig

    &lt;SSLHostConfig hostName=&quot;test.test&quot;
                       protocols=&quot;TLSv1.2&quot;&gt;
            &lt;Certificate certificateFile=&quot;/etc/letsencrypt/archive/miniimagesvideos.com/cert2.pem&quot;                  certificateKeyFile=&quot;/etc/letsencrypt/archive/miniimagesvideos.com/privkey2.pem&quot;              certificateChainFile=&quot;/etc/letsencrypt/archive/miniimagesvideos.com/chain2.pem&quot; /&gt;
        &lt;/SSLHostConfig&gt;
  &lt;/Connector&gt;

In the context.xml the following needs to be added

&lt;Loader jakartaConverter=&quot;TOMCAT&quot; /&gt; 

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.

huangapple
  • 本文由 发表于 2023年5月15日 10:49:40
  • 转载请务必保留本文链接:https://go.coder-hub.com/76250597.html
匿名

发表评论

匿名网友

:?: :razz: :sad: :evil: :!: :smile: :oops: :grin: :eek: :shock: :???: :cool: :lol: :mad: :twisted: :roll: :wink: :idea: :arrow: :neutral: :cry: :mrgreen:

确定