使用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/