You need to enable JavaScript to run this app.
优惠活动
大模型
产品
解决方案
定价
更多

Docker Build部署Cloud Run失败:端口8080无法监听的排查与解决

本地Docker构建镜像部署Cloud Run失败,Cloud Build构建正常的排查与解决

问题场景

本地执行以下Docker构建+Cloud Run部署命令时持续失败:

docker build --force-rm -t $IMAGE_NAME . --no-cache

docker push $IMAGE_NAME:latest

gcloud run deploy $CONTAINER_NAME \
--image $IMAGE_NAME:latest \
--region $REGION \
--platform managed \
--allow-unauthenticated

但使用Cloud Build构建部署则完全正常:

gcloud builds submit --tag $IMAGE_NAME
gcloud run deploy $CONTAINER_NAME \
--image $IMAGE_NAME:latest \
--region $REGION \
--platform managed \
--allow-unauthenticated

报错信息

Cloud Run返回部署失败提示:

ERROR: (gcloud.run.deploy) Revision 'test-app-container-00004-vlm' is not ready and cannot serve traffic. The user-provided container failed to start and listen on the port defined by the PORT=8080 environment variable. Logs for this revision might contain more information.

查看Cloud Run日志,发现以下关键信息:

WARNING 2024-09-12 Application exec likely failed
ERROR 2024-09-12 Default STARTUP TCP probe failed 1 time consecutively for container "example-1" on port 8080. The instance was not started.

排查与解决

通过日志推测是应用启动失败导致无法监听8080端口,进一步定位到问题根源:Mac Apple芯片环境下,本地docker build默认使用linux/arm64平台构建镜像,而Cloud Run运行环境为linux/amd64,跨平台构建的镜像存在兼容性问题,导致应用启动异常。

解决方法:在docker build命令中显式指定--platform linux/amd64参数,重新构建并部署:

docker build --force-rm -t $IMAGE_NAME . --no-cache --platform linux/amd64

docker push $IMAGE_NAME:latest

gcloud run deploy $CONTAINER_NAME \
--image $IMAGE_NAME:latest \
--region $REGION \
--platform managed \
--allow-unauthenticated

修改后部署恢复正常。

内容的提问来源于stack exchange,提问作者LAWRENCE

相关产品推荐
方舟 Agent Plan

超全模态模型 × Harness 升级,最新支持 Deepseek-V4.1-Flash、GLM-5.3 系列、Doubao-Seedream-5.0-pro、Kimi-K3 (部分), 限时 9.9 元起

最近更新时间:2026.06.18 11:32:47