如何在 Google Container Registry 中删除推送的镜像

How to remove a pushed image in Google Container Registry

是否可以从 Google Container Registry 中删除推送的映像?

我的意思是没有直接处理Google云存储目录。

谢谢!

我用 Google 为同一个问题开了一张票,他们回复说目前不可能,但请继续关注,因为他们确实计划很快将其添加到 UI。

在此期间,您必须使用存储浏览器删除任何您想要删除的内容。

在当前UI及其实现中,您只能删除标签,不会删除底层图像。

如果它是 Docker V2 图像,您可以从命令行使用 Docker 注册表 API 删除图像,首先删除标签,然后删除清单。回复末尾有更多相关信息。

如果是DockerV1镜像,没有"docker"删除镜像的方法,但是可以在GCS中删除。

我们正在实施新功能,使您能够删除 V2 标签和图像。

有关使用 Docker 注册表 V2 API 从命令行删除 V2 images/tags 的详细信息:

export REGISTRY=gcr.io
export REPOSITORY=foo/bar
# Next line will dump all the manifests and the tags pointing to the manifests:
curl -u _token:$(gcloud auth print-access-token) https://$REGISTRY/v2/$REPOSITORY/tags/list 2>/dev/null | python -mjson.tool
# You will see output like this:
{
    ...
    "manifest": {
        "sha256:2aa676...": {},
        "sha256:95de3c...": {
            "tag": [
                "centos7.0.1406",
                "centos8.8",
                ...
            ]
        },
        ...
    },
    "name": "foo/bar",
    "tags": [
        "centos7.0.1406",
        "centos8.8",
        ...
    ]
}

# Find the image/manifest you want to delete, first delete all its tags,
# then delete the manifest, by using:
curl -X DELETE -u _token:$(gcloud auth print-access-token) https://$REGISTRY/v2/$REPOSITORY/manifests/xxxx 
# where xxxx is the tag or manifest you want to delete
# (yes, you delete tag and manifest using the same REST api)

现在 Google Container Registry migrated to v2,您可以:

  1. 删除标签(通过Google云平台网页UI,目前不知道CLI方法,可能稍后Google Container Engine API会支持它,或 Docker 注册表)。
  2. 删除 manifests 这实际上会删除文件并释放 space 在您的存储空间中(例如使用 Google Cloud Shell):

    $ export REGISTRY=gcr.io
    $ export REPOSITORY=my-registry-name/my-image-name
    $ export TOKEN=$(gcloud auth print-access-token)
    $ curl -u _token:$TOKEN https://$REGISTRY/v2/$REPOSITORY/tags/list 2>/dev/null | python -m json.tool | grep -Po 'sha256:[^"]*' | xargs -i sh -c "curl -X DELETE -u _token:$TOKEN https://$REGISTRY/v2/$REPOSITORY/manifests/{} 2>/dev/null | python -m json.tool"
    

注意:它不会删除标签使用的清单。

注意 2:Docker Registry 升级到 v2.1.1 后,可以调用 GET /v2/_catalog 列出所有图像,并 运行 对所有图像执行上述操作以简化过程。

更新

Google Cloud Web UI 现在允许删除图像(参见

here 所述,您可以使用以下 gcloud 命令从 Google Container Registry 中删除映像:

gcloud container images delete IMAGE_NAMES [IMAGE_NAMES …] [GLOBAL-FLAG …]

在此处检查如何删除图像。

使用 CLI

gcloud container images delete [HOSTNAME]/[PROJECT-ID]/[IMAGE]

https://cloud.google.com/container-registry/docs/managing#deleting_images