16

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

I mean without handling the Google Cloud Storage directory directly.

Thanks!

ahmet alp balkan
  • 42,679
  • 38
  • 138
  • 214
Hernan
  • 212
  • 2
  • 9

5 Answers5

7

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)
Wei
  • 309
  • 2
  • 2
7

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 …]
ahmet alp balkan
  • 42,679
  • 38
  • 138
  • 214
Franck
  • 86
  • 1
  • 2
6

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)

Community
  • 1
  • 1
Wernight
  • 36,122
  • 25
  • 118
  • 131
  • To delete e.g. the “latest” tag, send a DELETE request to https://$REGISTRY/v2/$REPOSITORY/manifests/latest, i.e. the manifests handler seems to accept both digests and tag names. – Michael Aug 13 '16 at 14:48
5

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.

coleca
  • 347
  • 3
  • 12
  • 1
    The feature for adding/deleting tags in the UI should now be live (or at least rolling out). Let us know if you have any issues either here or via gcr-contact@google.com. – mattmoor Jul 22 '15 at 15:54
  • @mattmoor What about images without tags? – Josh Jul 29 '15 at 21:46
  • Sorry, images without tags is a bug in the current deletion code. We leave around a file named _index_images, which is safe to delete via the storage browser. A fix is on the way. – mattmoor Aug 03 '15 at 20:46
  • 2
    @mattmoor I've deleted tags in UI, but images are still here. Is it supposed to be garbage collected somehow? – Severin Pappadeux Aug 05 '15 at 02:52
  • @coleca How I could delete image using storage browser? Any help will be great, thank you – Severin Pappadeux Aug 05 '15 at 02:53
  • I am still seeing the storage browser to REMOVE the latest TAG only.. Is there anyway to delete / update with new content for the same gcr.io name ? – Raj Rajen Nov 19 '15 at 21:08
  • @mattmoor You mentioned: "The feature for adding/deleting tags in the UI should now be live (or at least rolling out)." Is there a document on how to use this feature? I didn't see this feature from the UI. From Google cloud console, I selected Container Engine -> Container Registry, where it always shows a help message even after I pushed a few images – Jake W Jan 06 '16 at 23:21
  • @coleca Do you have a link for the ticket you opened with Google? I would like to see what the status is. – Jake W Jan 06 '16 at 23:24
1

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

mrjumpy
  • 64
  • 10