容器无法启动.无法启动,然后在PORT环境变量定义的端口上侦听 [英] Container failed to start. Failed to start and then listen on the port defined by the PORT environment variable

查看:47
本文介绍了容器无法启动.无法启动,然后在PORT环境变量定义的端口上侦听的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我构建了容器映像,但是当我尝试从 gcloud 命令行或Cloud Console部署它时,出现以下错误:容器无法启动.无法启动,然后启动侦听PORT环境变量定义的端口."

I built my container image, but when I try to deploy it from the gcloud command line or the Cloud Console, I get the following error: "Container failed to start. Failed to start and then listen on the port defined by the PORT environment variable."

推荐答案

在您的代码中,您可能未在侦听传入的HTTP请求,或者正在侦听错误端口上的传入请求.

In your code, you probably aren't listening for incoming HTTP requests, or you're listening for incoming requests on the wrong port.

Cloud Run容器运行时合同中所述,您的容器必须在Cloud Run定义并在 $ PORT 环境变量中提供的端口上侦听传入的HTTP请求.

As documented in the Cloud Run container runtime contract, your container must listen for incoming HTTP requests on the port that is defined by Cloud Run and provided in the $PORT environment variable.

如果您的容器无法在预期的端口上侦听,则修订运行状况检查将失败,修订将处于错误状态,并且流量不会路由到该状态.

If your container fails to listen on the expected port, the revision health check will fail, the revision will be in an error state and the traffic will not be routed to it.

例如,在带有Express的Node.js中,您应该使用:

For example, in Node.js with Express, you should use :

const port = process.env.PORT || 8080;
app.listen(port, () => {
  console.log('Hello world listening on port', port);
});

在Go中:

port := os.Getenv("PORT")
if port == "" {
        port = "8080"
}
log.Fatal(http.ListenAndServe(fmt.Sprintf(":%s", port), nil))

这篇关于容器无法启动.无法启动,然后在PORT环境变量定义的端口上侦听的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆