16

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

我的意思是直接处理 Google Cloud Storage 目录。

谢谢!

4

5 回答 5

7

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

如果是 Docker V2 镜像,您可以从命令行使用 Docker Registry API 删除镜像,方法是先删除标签,然后删除清单。更多关于这个在回复的末尾。

如果是 Docker V1 镜像,没有“docker”方式删除镜像,但是可以在 GCS 中删除镜像。

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

有关使用 Docker Registry V2 API 从命令行删除 V2 映像/标签的详细信息:

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)
于 2016-03-21T18:18:45.897 回答
7

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

gcloud container images delete IMAGE_NAMES [IMAGE_NAMES …] [GLOBAL-FLAG …]
于 2017-02-22T12:59:37.380 回答
6

现在Google Container Registry 已迁移到 v2,您可以:

  1. 移除标签(通过 Google Cloud Platform web UI,目前不知道 CLI 方法,可能以后Google Container Engine API会支持它,或者 Docker Registry)。
  2. 删除清单,这实际上会删除您存储中的文件和可用空间(例如使用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 现在允许删除图像(请参阅https://stackoverflow.com/a/33791574/167897

于 2016-05-25T13:56:32.897 回答
5

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

与此同时,您必须使用存储浏览器来删除您想要删除的任何内容。

于 2015-07-21T02:15:10.547 回答
1

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

使用命令行

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

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

于 2017-09-20T04:14:26.820 回答