【问题标题】:How to remove a pushed image in Google Container Registry如何在 Google Container Registry 中删除推送的镜像
【发布时间】:2015-10-10 00:22:07
【问题描述】:

是否可以从 Google Container Registry 中删除推送的映像

我的意思是直接处理 Google Cloud Storage 目录。

谢谢!

【问题讨论】:

    标签: docker google-container-registry


    【解决方案1】:

    正如here 解释的那样,您可以使用以下 gcloud 命令从 Google Container Registry 中删除映像:

    gcloud container images delete IMAGE_NAMES [IMAGE_NAMES …] [GLOBAL-FLAG …]
    

    【讨论】:

      【解决方案2】:

      目前的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)
      

      【讨论】:

      • v2 现在应该为 Google Container 发布了。
      【解决方案3】:

      现在Google Container Registry migrated to v2,您可以:

      1. 移除tags(通过谷歌云平台web UI,目前不知道CLI方法,可能以后Google Container Engine API会支持,或者Docker Registry)。
      2. 删除 ma​​nifests,这实际上会删除您存储中的文件和可用空间(例如使用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

      【讨论】:

      • 删除例如“最新”标签,向 https://$REGISTRY/v2/$REPOSITORY/manifests/latest 发送 DELETE 请求,即清单处理程序似乎同时接受摘要和标签名称。
      【解决方案4】:

      我为同样的问题向 Google 开了一张票,他们回复说目前不可能,但请继续关注,因为他们确实计划很快将其添加到 UI。

      与此同时,您必须使用存储浏览器来删除您想要删除的任何内容。

      【讨论】:

      • 在 UI 中添加/删除标签的功能现在应该已经上线(或至少推出)。如果您有任何问题,请在此处或通过 gcr-contact@google.com 告诉我们。
      • @mattmoor 没有标签的图片呢?
      • 对不起,没有标签的图像是当前删除代码中的一个错误。我们留下一个名为 _index_images 的文件,可以通过存储浏览器安全地删除该文件。正在修复中。
      • @mattmoor 我已经删除了 UI 中的标签,但图像仍然存在。是否应该以某种方式进行垃圾收集?
      • @coleca 如何使用存储浏览器删除图像?任何帮助都会很棒,谢谢
      【解决方案5】:

      在此处查看如何删除图像。

      使用 CLI

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

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

      【讨论】:

        猜你喜欢
        • 1970-01-01
        • 1970-01-01
        • 2018-10-31
        • 1970-01-01
        • 2021-12-10
        • 1970-01-01
        • 2016-05-11
        • 1970-01-01
        • 1970-01-01
        相关资源
        最近更新 更多