是否可以从 Google Container Registry 中删除推送的图像?
我的意思是不直接处理 Google Cloud Storage 目录。
谢谢!
是否可以从 Google Container Registry 中删除推送的图像?
我的意思是不直接处理 Google Cloud Storage 目录。
谢谢!
使用当前的 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)
如此处所述,您可以使用以下 gcloud 命令从 Google Container Registry 中删除映像:
gcloud container images delete IMAGE_NAMES [IMAGE_NAMES …] [GLOBAL-FLAG …]
现在Google Container Registry 已迁移到 v2,您可以:
删除清单,这实际上会删除您存储中的文件和可用空间(例如使用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)
我为同样的问题向谷歌开了一张票,他们回复说目前不可能,但请继续关注,因为他们确实计划很快将其添加到 UI 中。
与此同时,您必须使用存储浏览器来删除您想要删除的任何内容。
在此处查看如何删除图像。
使用命令行
gcloud container images delete [HOSTNAME]/[PROJECT-ID]/[IMAGE]
https://cloud.google.com/container-registry/docs/managing#deleting_images