【问题标题】:(gcloud.run.deploy) Cloud Run error: Container failed to start. Failed to start and then listen on the port(gcloud.run.deploy) Cloud Run 错误:容器无法启动。启动失败,然后监听端口
【发布时间】:2020-01-31 13:40:50
【问题描述】:

使用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);

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

【问题讨论】:

  • 如果在容器启动时记录了任何错误怎么办?您能否收集所有工件并将它们放在临时 GitHub 存储库中并发布链接。也许某个善良的灵魂可能会尝试重建?

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


【解决方案1】:

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

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

【讨论】:

  • 谢谢,我解决了这个特殊问题。不过,我现在还有另一个问题,docker run .. 不起作用。 .. 是否代表其他东西?
  • @SeanDezoysa,参考docker run更新了答案。
【解决方案2】:

这里同样的错误。我解决了增加timeout的问题。

【讨论】:

    猜你喜欢
    • 2021-06-13
    • 2021-05-24
    • 2021-09-05
    • 2021-11-10
    • 2021-11-10
    • 2023-01-26
    • 2020-04-18
    • 2021-10-07
    • 1970-01-01
    相关资源
    最近更新 更多