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

Docker Build持续使用过期文件内容的问题排查求助

问题排查与解决方案

核心问题分析

构建镜像后,镜像内仍保留旧版本的init_td_and_run.sh脚本(包含gcloud命令、指向td-grpc-bootstrap-0.18.0),即使使用--no-cache构建也未生效,导致Cloud Run部署后报错。


分步排查与解决

1. 验证本地脚本与构建上下文

  • 直接检查本地修改后的examples/cpp/xds/init_td_and_run.sh:
    • 确认已删除所有gcloud相关命令
    • 确认下载归档的命令已改为td-grpc-bootstrap-0.18.1.tar.gz,解压路径对应0.18.1版本
  • 检查.dockerignore文件:确保examples/cpp/xds/init_td_and_run.sh未被排除在构建上下文外

2. 构建时追踪文件复制过程

添加--progress=plain参数重新构建,查看每一步输出,确认脚本是否被正确复制:

docker build --no-cache --progress=plain -f examples/cpp/xds/Dockerfile.client -t grpc/xds-example-cpp-client-with-td-init .

重点关注:

  • RUN cp -rL /workdir/examples/cpp/xds/init_td_and_run.sh /artifacts/步骤的输出,确认是否复制了最新的脚本文件
  • COPY --from=0 /artifacts ./步骤,确认文件是否正确从阶段0传递到最终镜像

3. 本地验证镜像内容(关键步骤)

构建完成后,不要直接推送,先本地运行容器查看脚本内容:

docker run --rm grpc/xds-example-cpp-client-with-td-init cat /init_td_and_run.sh
  • 如果输出是旧脚本:问题出在构建环节,继续下一步
  • 如果输出是新脚本:问题出在镜像推送或Cloud Run缓存,跳至步骤5

4. 修复构建环节的文件传递逻辑

原Dockerfile通过阶段0中转复制脚本,容易出现中间层缓存或路径错误,建议直接在最终阶段COPY本地脚本,替换原有逻辑:
将Dockerfile中:

RUN cp -rL /workdir/examples/cpp/xds/init_td_and_run.sh /artifacts/
COPY --from=0 /artifacts ./

替换为:

COPY examples/cpp/xds/init_td_and_run.sh ./

直接从构建上下文复制最新脚本,减少中间环节出错概率。

5. 确保Cloud Run拉取最新镜像

如果本地镜像内容正确,但Cloud Run仍使用旧镜像:

  • 推送镜像时,除了latest标签,额外添加唯一版本标签(如基于提交哈希),避免latest标签的缓存歧义:
    docker tag grpc/xds-example-cpp-client-with-td-init:latest grpc/xds-example-cpp-client-with-td-init:v1.0.0
    docker push grpc/xds-example-cpp-client-with-td-init:v1.0.0
    
  • 部署Cloud Run时,使用版本标签而非latest,并添加--no-cache参数强制拉取最新镜像:
    gcloud alpha run deploy cloudrun-client --region=us-central1 --image=grpc/xds-example-cpp-client-with-td-init:v1.0.0 --args=--xds_creds=true,--target=xds:///helloworld --network=default --subnet=default --mesh=$MESH --no-cache
    

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

相关产品推荐
方舟 Agent Plan

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

最近更新时间:2026.06.15 23:53:12