How to remove a pushed image in Google Container Registry

后端 未结 5 1143
春和景丽
春和景丽 2021-01-04 02:06

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

I mean without handling the Google Cloud Storage directory

5条回答
  •  陌清茗
    陌清茗 (楼主)
    2021-01-04 02:45

    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)

提交回复
热议问题