How to remove a pushed image in Google Container R

2020-03-01 05:45发布

Is it possible to remove a pushed image from Google Container Registry?

I mean without handling the Google Cloud Storage directory directly.

Thanks!

5条回答
贪生不怕死
2楼-- · 2020-03-01 05:55

As explained here you can delete an image from Google Container Registry with the following gcloud command:

gcloud container images delete IMAGE_NAMES [IMAGE_NAMES …] [GLOBAL-FLAG …]
查看更多
够拽才男人
3楼-- · 2020-03-01 05:55

With current UI and its implementation, you can only delete tags, the underlying images will not be deleted.

If it is a Docker V2 images, from command line you can delete the image using Docker Registry API , by deleting the tags first, and then deleting the manifest. More about this at the end of the reply.

If it is a Docker V1 image, there is no "docker" way to delete the image, but you can delete the image in GCS.

We are implementing new features that will enable you to delete V2 tags and images.

Details about deleting V2 images/tags from command line using Docker Registry V2 API:

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)
查看更多
贼婆χ
4楼-- · 2020-03-01 06:12

I opened a ticket with Google for this same question and they responded back that it is not possible currently but to stay tuned because they do plan on adding it to the UI shortly.

In the meantime you have to use the storage browser to delete any that you want removed.

查看更多
再贱就再见
5楼-- · 2020-03-01 06:14

Check how to delete images here.

Using CLI

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

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

查看更多
聊天终结者
6楼-- · 2020-03-01 06:16

Now that Google Container Registry migrated to v2, you can:

  1. Remove tags (via Google Cloud Platform web UI, currently no know CLI method, may be later the Google Container Engine API will support it, or Docker Registry).
  2. Remove manifests which will actually remove files and free space in your storage (use for example the 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"
    

Note: It'll not delete manifest that are used by tags.

Note 2: Once Docker Registry upgrades to v2.1.1 one may call GET /v2/_catalog to list all images and run the above on all images to simplify the process.

Update

Google Cloud Web UI allows now to delete images (see https://stackoverflow.com/a/33791574/167897)

查看更多
登录 后发表回答