部署Google Cloud Function报错:Python构建镜像未找到
解决Cloud Function构建失败:找不到Python构建镜像
问题重现
部署1代事件驱动型Google Cloud Function(Python3.10)时,构建过程报错,无法找到指定的构建镜像:
[12:56:18 PM] - Preparing function sources ... [12:56:19 PM] - Building function sources ... [12:56:19 PM] - Building 1st gen event-driven function might take longer than usual [12:56:19 PM] - Error: Command failed: cd /gcf-working-dir/function-sources && pack build gcf-ui-function --builder gcr.io/gae-runtimes/buildpacks/google-gae-22/python/builder --pull-policy if-not-present --env GOOGLE_FUNCTION_TARGET=hello_pubsub --env GOOGLE_FUNCTION_SIGNATURE_TYPE=event --env GOOGLE_DEVMODE=1 --env GOOGLE_RUNTIME_VERSION=3.10 ERROR: failed to build: failed to fetch builder image 'gcr.io/gae-runtimes/buildpacks/google-gae-22/python/builder:latest': image 'gcr.io/gae-runtimes/buildpacks/google-gae-22/python/builder:latest' does not exist on the daemon: not found
解决方案
1. 修正构建镜像地址
报错中的gcr.io/gae-runtimes/buildpacks/google-gae-22/python/builder路径有误,官方针对Python的通用构建镜像地址应为:
gcr.io/gae-runtimes/buildpacks/python/builder
如果是通过本地pack命令部署,直接修改--builder参数即可;如果是通过Cloud Console部署,建议切换到命令行部署以避免后台配置异常。
2. 强制拉取构建镜像
本地Docker daemon可能未缓存目标镜像,执行以下命令手动拉取:
docker pull gcr.io/gae-runtimes/buildpacks/python/builder:latest
拉取完成后重新触发构建。
3. 使用gcloud命令行部署替代UI
Cloud Console的构建流程偶尔会出现镜像路径配置问题,改用gcloud命令行部署更稳定:
gcloud functions deploy hello_pubsub \ --runtime python310 \ --trigger-topic YOUR_PUBSUB_TOPIC_NAME \ --entry-point hello_pubsub
替换YOUR_PUBSUB_TOPIC_NAME为你的Pub/Sub主题名称。
4. 检查Docker运行状态
确保本地Docker daemon已启动,且当前用户拥有Docker操作权限(可通过docker ps命令验证)。
内容的提问来源于stack exchange,提问作者Internet Presence
相关产品推荐
相关产品推荐

