简体   繁体   English

将 docker 镜像部署到云运行时如何解决“容器启动失败错误”

[英]How to resolve "container failed to start error" while deploying a docker image to cloud run

Problem statement: I have created a docker application ( a simple python code) and trying to deploy and automate run using Google Cloudrun but each time during deployment I see the below error:问题陈述:我创建了一个 docker 应用程序(一个简单的 python 代码)并尝试使用 Google Cloudrun 进行部署和自动运行,但每次在部署期间我都会看到以下错误:

command:命令:

gcloud run deploy my_service_name --image gcr.io/project-id/image_name

Error错误

 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 info
rmation.                                                                                                                                                                                                   
  X Creating Revision... 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 inform
  ation.                                                                                                                                                                                                   
  . Routing traffic...                                                                                                                                                                                     
Deployment failed            

My Dockerfile我的 Dockerfile

#FROM python:3.8
FROM python:latest
# Copy application dependency manifests to the container image.
COPY requirements.txt ./
# Install production dependencies.
RUN pip install -r requirements.txt
# Copy main 
COPY main.py ./
ENV PORT = 8080
CMD [ "python", "./main.py" ]

There is nothing fancy in my python program just running a bunch of sql queries and updating the BQ table.在我的 python 程序中没有什么特别的,只是运行一堆 sql 查询并更新 BQ 表。

I have used the troubleshooting steps listed by Google and the container runs on my local without any issue.我已经使用了 Google 列出的故障排除步骤,并且容器在我的本地运行没有任何问题。

Can someone please guide me as to where am I going wrong?有人可以指导我哪里出错了吗?

Edit: Updated the Dockerfile to ENV PORT=8080 (removed the space).编辑:将 Dockerfile 更新为 ENV PORT=8080(删除了空格)。 Still receiving the same error.仍然收到相同的错误。 deployment Logs below下面的部署日志

Deployment failed                                                                                                                                                                                          
DEBUG: (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.
Traceback (most recent call last):
  File "/Users/analyst045/Documents/google-cloud-sdk/lib/googlecloudsdk/calliope/cli.py", line 983, in Execute
    resources = calliope_command.Run(cli=self, args=args)
  File "/Users/analyst045/Documents/google-cloud-sdk/lib/googlecloudsdk/calliope/backend.py", line 807, in Run
    resources = command_instance.Run(args)
  File "/Users/analyst045/Documents/google-cloud-sdk/lib/surface/run/deploy.py", line 258, in Run
    build_log_url=build_log_url)
  File "/Users/analyst045/Documents/google-cloud-sdk/lib/googlecloudsdk/command_lib/run/serverless_operations.py", line 1087, in ReleaseService
    self.WaitForCondition(poller)
  File "/Users/analyst045/Documents/google-cloud-sdk/lib/googlecloudsdk/command_lib/run/serverless_operations.py", line 594, in WaitForCondition
    return waiter.PollUntilDone(poller, None, wait_ceiling_ms=1000)
  File "/Users/analyst045/Documents/google-cloud-sdk/lib/googlecloudsdk/api_lib/util/waiter.py", line 326, in PollUntilDone
    sleep_ms=sleep_ms)
  File "/Users/analyst045/Documents/google-cloud-sdk/lib/googlecloudsdk/core/util/retry.py", line 219, in RetryOnResult
    result = func(*args, **kwargs)
  File "/Users/analyst045/Documents/google-cloud-sdk/lib/googlecloudsdk/command_lib/run/serverless_operations.py", line 251, in Poll
    self._PollTerminalSubconditions(conditions, conditions_message)
  File "/Users/analyst045/Documents/google-cloud-sdk/lib/googlecloudsdk/command_lib/run/serverless_operations.py", line 230, in _PollTerminalSubconditions
    self._PossiblyFailStage(condition, message)
  File "/Users/analyst045/Documents/google-cloud-sdk/lib/googlecloudsdk/command_lib/run/serverless_operations.py", line 349, in _PossiblyFailStage
    message)
  File "/Users/analyst045/Documents/google-cloud-sdk/lib/googlecloudsdk/core/console/progress_tracker.py", line 915, in FailStage
    raise failure_exception  # pylint: disable=raising-bad-type
DeploymentFailedError: 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.
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.

Logs below:日志如下:

{
 insertId: "5ec6519000ca44b34efd"  
 labels: {
  instanceId: "00bf4bf02dd520b9906e825b7333299aac62e9e4f12e4090ccd3b3bfd2435203c13fbe3c09193bd6dd408286adf939dff830"   
 }
 logName: "projects/project-name/logs/run.googleapis.com%2Fvarlog%2Fsystem"  
 receiveTimestamp: "2020-05-18T10:46:09.076605834Z"  
 resource: {
  labels: {
   configuration_name: "measurement-protocol-hit"    
   location: "us-central1"    
   project_id: "project-id"    
   revision_name: "measurement-protocol-hit-00001-det"    
   service_name: "measurement-protocol-hit"    
  }
  type: "cloud_run_revision"   
 }
 severity: "WARNING"  
 textPayload: "Container called exit(0)."  
 timestamp: "2020-05-18T10:36:09.068639979Z"  
}

You should not do this:你不应该这样做:

ENV PORT = 8080

Not only as @supersam654 said it is the wrong syntax, PORT environment variable will be passed to your application by Cloud Run ––you don't pass it yourself like this.不仅如@supersam654 所说,这是错误的语法, PORT环境变量将由 Cloud Run 传递给您的应用程序——您不会像这样自己传递它。

As the has error said multiple times (what you posted is not "detailed logs"), you should:由于多次出现错误(您发布的不是“详细日志”),您应该:

Logs for this revision might contain more information.此修订的日志可能包含更多信息。

So go to https://console.cloud.google.com/run and fetch logs for this application.所以 go 到https://console.cloud.google.com/ 运行并获取此应用程序的日志。

You should probably make sure you test your container locally before deploying.您可能应该确保在部署之前在本地测试您的容器。 Instructions can be found here: https://cloud.google.com/run/docs/testing/local说明可在此处找到: https://cloud.google.com/run/docs/testing/local

Based on the Dockerfile reference , you can specify a port in one of two ways:根据Dockerfile 参考,您可以通过以下两种方式之一指定端口:

ENV <key> <value>
ENV <key>=<value> ...

Because you have spaces around = , Docker thinks you're using the first form where your key is PORT and your value is = 8000 (which is not a number and probably why Cloud Run isn't working).因为=周围有空格,所以 Docker 认为您使用的是第一种形式,其中您的键是PORT并且您的值为= 8000 (这不是数字,可能是 Cloud Run 无法正常工作的原因)。

To fix it, either specify the port without spaces ( ENV PORT=8000 ) or without an equals sign ( ENV PORT 8000 ).要修复它,请指定不带空格的端口 ( ENV PORT=8000 ) 或不带等号 ( ENV PORT 8000 )。

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

相关问题 GCP Cloud Run 部署 Docker 容器未启动,因为 nginx 图像无法找到 error.log - GCP Cloud Run deployed Docker container does not start because of nginx image is failing to find error.log Google Cloud Run - 容器无法启动解决方法 - Google Cloud Run - Container failed to start workarounds “Cloud Run 错误:容器启动失败。无法启动然后侦听 PORT 环境变量定义的端口。” - "Cloud Run error: Container failed to start. Failed to start and then listen on the port defined by the PORT environment variable." Cloud Run 中 Docker 容器上的 POST 出现 405 错误 - 405 error for POST on Docker Container in Cloud Run 在 Google Cloud Run 中部署多阶段 Docker 映像 - Deploying multi-stage Docker image in Google Cloud Run Cloud Run 错误:容器无法启动。 无法启动然后侦听 PORT 环境变量定义的端口。 - Django - Cloud Run error: Container failed to start. Failed to start and then listen on the port defined by the PORT environment variable. - Django 如何在 Cloud Run 中部署带卷的 docker 容器 - How to Deploy a docker container with volume in Cloud Run Docker 容器因“无法为新会话启动线程”错误而失败 - Docker container failing with "failed to start a thread for the new session" error 将 docker-compose 部署到 Cloud Run 或 GCP? - Deploying docker-compose to Cloud Run OR GCP? Cloud Run Docker 容器 - 如何访问 VM 上的数据库? - Cloud Run Docker container - How to access DB on VM?
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM