如何删除Google容器注册表中的推送图像

Her*_*nan 16 docker google-container-registry

是否可以从Google容器注册表中删除推送的图像

我的意思是直接处理Google云端存储目录.

谢谢!

Wei*_*Wei 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)
Run Code Online (Sandbox Code Playgroud)


小智 7

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

gcloud container images delete IMAGE_NAMES [IMAGE_NAMES …] [GLOBAL-FLAG …]
Run Code Online (Sandbox Code Playgroud)


Wer*_*ght 6

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

  1. 删除标签(通过Google Cloud Platform Web UI,目前还不知道CLI方法,以后可能会支持Google容器引擎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"
    
    Run Code Online (Sandbox Code Playgroud)

注意:它不会删除标记使用的清单.

注意2:一旦Docker Registry升级到v2.1.1,可以调用GET /v2/_catalog列出所有图像并在所有图像上运行上面的操作以简化过程.

更新

Google Cloud Web UI现在可以删除图片(请参阅/sf/answers/2365410211/)


col*_*eca 5

我为谷歌开了一张同样问题的机票,他们回复说目前不可能继续关注,因为他们计划很快将其添加到用户界面.

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

  • @mattmoor我在UI中删除了标签,但图片仍然在这里.应该以某种方式收集垃圾吗? (2认同)