如何删除Google容器registry中的推送图片
是否可以从Google容器registry中删除推送的图像 ?
我的意思是不直接处理Google Cloud Storage目录。
谢谢!
如此处所述,您可以使用以下gcloud命令从Google Container Registry中删除图像:
gcloud beta container images delete IMAGE_NAMES [IMAGE_NAMES …] [GLOBAL-FLAG …]
使用当前的用户界面及其实现,您只能删除标签,底层的图像不会被删除。
如果它是Docker V2映像,则可以通过命令行删除使用Docker Registry API的映像,先删除标记,然后删除清单。 更多关于这个在答复结束。
如果它是一个Docker V1镜像,没有“docker”的方式来删除镜像,但是可以在GCS中删除镜像。
我们正在实施新的function,使您能够删除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)
现在Google Container Registry已经迁移到v2 ,您可以:
- 删除标签 (通过Google云端平台Web UI,目前不知道CLI方法,可能稍后Google Container Engine API将支持它或Docker Registry)。
-
删除将实际删除存储中的文件和可用空间的清单 (例如,使用Google云端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 )
我在Google上为这个问题打开了一张票,他们回应说目前不可能,但是请继续关注,因为他们打算很快将其添加到UI中。
与此同时,您必须使用存储浏览器删除您要删除的任何内容。
检查如何删除图像。
使用CLI
gcloud container images delete [HOSTNAME]/[PROJECT-ID]/[IMAGE]
https://cloud.google.com/container-registry/docs/managing#deleting_images