google-cloud-platform - (gcloud.run.deploy)Cloud Run错误: Container failed to start.无法启动然后监听端口

标签 google-cloud-platform google-cloud-run

使用gcloud builds Submit --tag gcr.io/projectname/testserver成功部署容器后,然后尝试运行gcloud run deploy --image gcr.io/projectname/testserver --platform Managed 我看到这个错误:

$ gcloud run deploy --image gcr.io/projectname/testserver --platform managed
Please specify a region:
 // options removed

Service name (testserver):  
Allow unauthenticated invocations to [testserver] (y/N)?  y

Deploying container to Cloud Run service [testserver] in project [projectname] region [us-central1]
X Deploying new service... Cloud Run error:
 Container failed to start. Failed to start
 and then listen on the port defined by the
 PORT environment variable. Logs for this r
evision might contain more information.    
  X Creating Revision... Cloud Run error: C
  ontainer failed to start. Failed to start
   and then listen on the port defined by t
  he PORT environment variable. Logs for th
  is revision might contain more informatio
  n.                                       
  . Routing traffic...                     
  ✓ Setting IAM Policy...                  
Deployment failed                          
ERROR: (gcloud.run.deploy) Cloud Run error: Container failed to start. Failed to start and then listen on the port defined by the PORT environment variable. Logs for this revision might contain more information.

我有一个非常简单的项目,全部位于根文件夹中:

// Dockerfile
FROM node:12-slim

# Create app folder
WORKDIR /usr/src/app

# Install app deps. Copy the lock file
COPY package*.json ./
RUN npm install

COPY . ./
CMD ["node", "testServer.js"]
// testServer.js
const Koa = require("koa");
const koa = new Koa();

koa.get('/', async ctx => {
  ctx.body = "Koa server running"
});

const port = process.env.PORT || 8080;

koa.listen(port);

有谁知道这是什么原因造成的吗?从昨天开始就一直在尝试解决这个问题,现在即使是这个最小的项目,它似乎也存在问题。

最佳答案

我在您的代码中收到了TypeError: app.get is not a function。看起来这个语法已经过时了。重写为koa-router并且工作得很好。

无论如何,请尝试使用 docker run 在本地测试您的代码在部署之前。 并且您还可以在部署过程中在控制台->日志记录->云运行修订版->revision_id中找到更精确的错误消息

关于google-cloud-platform - (gcloud.run.deploy)Cloud Run错误: Container failed to start.无法启动然后监听端口,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/60005046/

相关文章:

google-app-engine - 跨多个区域的 AppEngine 负载均衡

google-cloud-platform - GCP(AI 平台笔记本)上的“服务器连接错误”

google-cloud-platform - Cloud Run 是否需要 NGINX?

google-cloud-platform - 云跑: Connecting to a CloudSQL database on another GCP Project

docker - 尝试在 google cloud run 上安装日志记录但失败

google-cloud-platform - 恢复 Google Cloud 默认网络

node.js - 来自源的错误 : Access to XMLHttpRequest at https://storage. googleapis.com/url 已被 CORS 策略阻止。使用 gcp SignedURl 时有 Angular

php - GCP Cloud运行容器服务:[pool www]未能写入套接字 '/run/php-fpm/www.sock'的ACL

google-cloud-platform - 安装 GCSFuse 时出现错误网关错误

python - Cloud Scheduler 调用的 GCP Cloud Run 应用程序的当前最大超时是多少