Laravel和Google Cloud:尚未准备好,无法提供流量。

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

Laravel and Google Cloud: is not ready and cannot serve traffic

问题

我在GCP上一直遇到这个错误:

步骤#2 - "部署":错误:(gcloud.run.services.update) 修订版 '########-00014-kit' 尚未准备好,无法提供流量。用户提供的容器未能启动并监听由 PORT=80 环境变量定义的端口。此修订版的日志可能包含更多信息。

这是我的当前Dockerfile:

从php:8.2

复制./gcloud-custom-configs/apache/到/etc/apache2/sites-available/
复制./到/var/www/html/

工作目录为/var/www/html

运行apt-get更新 && \
    apt-get安装 -y git zip unzip && \
    curl -sS https://getcomposer.org/installer | php -- --install-dir=/usr/local/bin --filename=composer && \
    composer install --no-dev --no-interaction --optimize-autoloader && \
    composer require google/cloud-logging google/cloud-error-reporting --with-all-dependencies && \
    chmod 0777 -R storage/ && \
    chmod 0777 -R bootstrap/cache/

暴露端口80(如果需要)

启动Apache服务器
英文:

I keep getting this error on GCP:

> Step #2 - "Deploy": ERROR: (gcloud.run.services.update) Revision
> '########-00014-kit' is not ready and cannot serve traffic. The
> user-provided container failed to start and listen on the port defined
> provided by the PORT=80 environment variable. Logs for this revision
> might contain more information.

This is my current dockerfile:

FROM php:8.2

COPY ./gcloud-custom-configs/apache/ /etc/apache2/sites-available/
COPY ./ /var/www/html/

# ADD ./ /var/www/html/
WORKDIR /var/www/html

# ADD ./gcloud-custom-configs/apache/ /etc/apache2/sites-available/

# COPY .env.example .env

RUN apt-get update && \
    apt-get install -y git zip unzip && \
    curl -sS https://getcomposer.org/installer | php -- --install-dir=/usr/local/bin --filename=composer && \
    composer install --no-dev --no-interaction --optimize-autoloader && \
    composer require google/cloud-logging google/cloud-error-reporting --with-all-dependencies && \
    chmod 0777 -R storage/ && \
    chmod 0777 -R bootstrap/cache/

# Expose port 80 (if necessary)
# EXPOSE 80

# Start the Apache server
# CMD ["apache2-foreground"]

Is there anything missing?

答案1

得分: 1

这个问题可能会在版本小于430.0.0的情况下得到修复,如文档中所述。请确保您的Google Cloud CLI版本小于430.0.0

另外,正如@John Hanley在评论中建议的那样,请确保在Docker中本地运行容器时,Laravel能正常工作。还要查看Cloud Run日志以查找错误消息,以找出错误的原因。

还可以参考这个故障排除文档,其中列出了可能导致错误的原因:

  1. 验证您是否可以在本地运行容器镜像。如果您的容器镜像无法在本地运行,您需要首先在本地诊断和修复问题。
  2. 检查您的容器是否在预期端口上监听请求,如容器运行时合同中所述。您的容器必须在Cloud Run定义的端口上监听传入请求,并在PORT环境变量中提供。请参阅配置容器以获取有关如何指定端口的说明。
  3. 检查您的容器是否在所有网络接口上监听,通常表示为0.0.0.0。
  4. 验证您的容器镜像是否按照容器运行时合同要求编译为64位Linux。
    注意:如果您在基于ARM的计算机上构建容器镜像,则在与Cloud Run一起使用时可能无法按预期工作。要解决此问题,请使用Cloud Build构建您的镜像。
  5. 使用Cloud Logging来查找stdout或stderr日志中的应用程序错误。您还可以在Error Reporting中查找捕获的崩溃信息(https://cloud.google.com/run/docs/error-reporting)。
    您可能需要更新您的代码或修复您的修订设置以解决错误或崩溃。您还可以在本地进行服务故障排除
英文:

This issue might be fixed with the version less than 430.0.0 as stated in the Documentation. Make sure your Google cloud CLI version is less than 430.0.0.

Also as @John Hanley suggested in the comments, Make sure Laravel works correctly when you run the container locally in Docker. Also Review the Cloud Run logs for error messages to find the cause of the error.

Also check with this Troubleshooting Document, which states the potential causes of the error:

> 1. Verify that you can run your container image locally. If your container image cannot run locally, you need to diagnose and fix the issue locally first.
>2. Check if your container is listening for requests on the expected port as documented in the container runtime contract. Your container must listen for incoming requests on the port that is defined by Cloud Run and provided in the PORT environment variable. See Configuring containers for instructions on how to specify the port.
>3. Check if your container is listening on all network interfaces, commonly denoted as 0.0.0.0.
>4. Verify that your container image is compiled for 64-bit Linux as required by the container runtime contract.
Note: If you build your container image on a ARM based machine, then it might not work as expected when used with Cloud Run. To solve this issue, build your image using Cloud Build.
>5. Use Cloud Logging to look for application errors in stdout or stderr logs. You can also look for crashes captured in Error Reporting.
You might need to update your code or your revision settings to fix errors or crashes. You can also troubleshoot your service locally.

huangapple
  • 本文由 发表于 2023年6月15日 14:52:58
  • 转载请务必保留本文链接:https://go.coder-hub.com/76479846.html
匿名

发表评论

匿名网友

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

确定