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

如何用PHP获取GCR或Artifact Registry中镜像的digest?

获取GCR容器镜像Digest的纯PHP方案需求

当前实现方式

我目前通过调用shell命令来获取镜像Digest,代码如下:

function findDigestForImage($imageNoDigest)
{
    $cmd = sprintf("gcloud container images describe %s --format 'value(image_summary.digest)'", $imageNoDigest);
    return rtrim(shell_exec($cmd));
}

执行的具体shell命令为:

gcloud container images describe eu.gcr.io/test/some-project:tag --format 'value(image_summary.digest)'

存在的问题

使用shell_exec这类函数并非理想方案,在代码中调用shell执行函数是非常糟糕的安全实践,因此我希望采用官方库纯代码实现,完全不依赖shell调用。

遇到的困境

我查阅了谷歌官方的PHP容器分析相关库的几乎所有代码,但该库缺乏完善的文档,加上自身PHP能力有限,无法找到合适的实现方法。


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

相关产品推荐
方舟 Agent Plan

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

最近更新时间:2026.07.14 20:15:00