部署到 Google Cloud Run 时 Docker 容器无法启动

Posted

技术标签:

【中文标题】部署到 Google Cloud Run 时 Docker 容器无法启动【英文标题】:Docker container failed to start when deploying to Google Cloud Run 【发布时间】:2020-11-20 02:13:31 【问题描述】:

我是 GCP 的新手,我正在尝试通过在连接到 BigQuery 并写入系统时间的 Docker 容器中部署一个简单的 R 脚本来自学。我正在关注这个很棒的教程:https://arbenkqiku.github.io/create-docker-image-with-r-and-deploy-as-cron-job-on-google-cloud

到目前为止,我有:

1.- 制作 R 脚本

library(bigrquery)
library(tidyverse)

bq_auth("/home/rstudio/xxxx-xxxx.json", email="xxxx@xxxx.com")

project = "xxxx-project"
dataset = "xxxx-dataset"
table = "xxxx-table"

job = insert_upload_job(project=project, data=dataset, table=table, write_disposition="WRITE_APPEND",
                values=Sys.time() %>% as_tibble(), billing=project)

2.- 制作 Dockerfile

FROM rocker/tidyverse:latest

RUN R -e "install.packages('bigrquery', repos='http://cran.us.r-project.org')"

ADD xxxx-xxxx.json /home/rstudio

ADD big-query-tutorial_forQuestion.R /home/rstudio

EXPOSE 8080

CMD ["Rscript", "/home/rstudio/big-query-tutorial.R", "--host", "0.0.0.0"]

3.- 在我的机器上本地成功运行容器,将系统时间写入 BigQuery

4.- 将容器推送到我在 Google Cloud 中的容器注册表

当我尝试使用 Google Cloud Console 将容器部署到 Cloud Run(完全托管)时,出现以下错误:

"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 URL:https://console.cloud.google.com/logs/xxxxxx"

当我查看日志时,我发现这些值得注意的条目:

1.- 一个警告说“Container called exit(0)”

2.- 两个错误说“容器沙箱:不支持的系统调用 setsockopt(0x8,0x0,0xb,0x3e78729eedc4,0x4,0x8)。您很可能可以放心地忽略此消息,这不是导致您可能正在解决的任何错误。请参阅https://gvisor.dev/c/linux/amd64/setsockopt 了解更多信息。"

当我检查 BigQuery 时,我发现系统时间已写入表中,即使容器未能部署。

当我使用教程中指定的端口 (8787) 时,Cloud Run 会抛出一个关于“Invalid ENTRYPOINT”的错误。

这个错误是什么意思?如何修复?非常感谢您的意见,因为我完全被卡住了!

谢谢!

H.

【问题讨论】:

您的容器必须提供类似于 Web 服务器的 HTTP 请求/响应系统。 Cloud Run 容器响应 HTTP 请求而运行。您的代码不符合要求。 cloud.google.com/run/docs/reference/container-contract 您的代码必须响应 TCP 端口 $PORT 上的 HTTP 请求(默认为 8080)。 【参考方案1】:

John 的评论是错误的正确来源:您需要公开一个侦听 $PORT 并响应 HTTP/1 HTTP/2 协议的网络服务器。

但是,我有一个解决方案。您可以为此使用Cloud Build。如果需要,只需使用您的容器名称和参数定义您的步骤

如果您需要有关此(奇怪)解决方法的更多指导,请告诉我。

【讨论】:

【参考方案2】:

来自 Google Cloud Run 的日志信息“Container Sandbox: Unsupported syscall setsockopt”记录为gVisor 的问题。

【讨论】:

gVisor的问题与他的实际问题无关。

以上是关于部署到 Google Cloud Run 时 Docker 容器无法启动的主要内容,如果未能解决你的问题,请参考以下文章