Cloud Run:“无法启动并侦听 PORT 环境变量定义的端口。” 当我使用8080时

Bal*_*Pap 34 google-cloud-platform dockerfile nuxt.js google-cloud-run

当我尝试在 Google Cloud Run 中运行容器时收到此错误消息。

type: Ready
status: 'False'
reason: HealthCheckContainerError
message: |-
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.
Run Code Online (Sandbox Code Playgroud)

我已经检查了以下内容,但对我没有任何帮助:

我的容器在本地运行,并且正在侦听默认端口,8080并将主机配置为0.0.0.0

我的 Dockerfile:

FROM node:10

WORKDIR /usr/src/app

ENV PORT 8080
ENV HOST 0.0.0.0

COPY package*.json ./

RUN npm install --only=production

COPY . .

RUN npm run build

CMD npm start
Run Code Online (Sandbox Code Playgroud)

知道为什么 Cloud Run 一直无法侦听端口吗?


项目 GitHub 存储库:

https://github.com/fodorpapbalazsdev/ssr-app

小智 150

请检查一下,您使用的是 M1 Macbook 吗?在面对这个问题一段时间后,我为自己找到了一个解决方案,可能不适合您,但只是为了与其他 MacBook 用户分享我发现的一些见解。

太长了;博士

--platform linux/amd64在将映像部署到 Cloud Run 之前使用该标志构建 Docker 容器

=================================================== ======

很长的故事:

除了container failed to start and listen to the $PORT错误之外,我的日志还显示以下内容:Application failed to start: Failed to create init process: failed to load /usr/local/bin/npm: exec format error。经过一番挖掘,发生这种情况的原因之一是我们尝试在不同的主机平台上运行 arm64 映像(在 M1 MacBook 上构建)。

GCP 在此页面上确实提到了Executables in the container image must be compiled for Linux 64-bit. Cloud Run specifically supports the Linux x86_64 ABI format.

我想这解释了为什么在 Cloud Build 上构建映像可以从本文中的其他答案中得出。

  • 这对我有用。完整命令:`docker buildx build --platform linux/amd64 -t image-name:v0.1.0 .`参考:[Docker Docs](https://docs.docker.com/desktop/multi-arch/) (7认同)
  • 在我为此浪费了比我愿意承认的更多的时间之后,这解决了我的问题。太感谢了。 (5认同)
  • `docker buildx build --platform linux/amd64 -t TAG_NAME 。` (3认同)