• 请不要在回答技术问题时复制粘贴 AI 生成的内容
JasonLaw
V2EX  ›  程序员

清理 docker registry 的旧镜像,有什么简单的方法吗?

  •  
  •   JasonLaw · May 25, 2021 · 2505 views
    This topic created in 2000 days ago, the information mentioned may be changed or developed.

    找了一圈,没有找到简单的方法。

    我具体描述一下我的需求:仓库有四个分支 current_feature, master, pre_production, production,其中 master 跟环境没有任何关系。current_feature 对应 dev 环境,pre_production 对应 pre_production 环境,production 对应 production 环境。镜像的标签是 current_feature-latest, current_feature-{shortCommitHash}, pre_production-latest, pre_production-{shortCommitHash}, production-latest, production-{shortCommitHash}。我想删除掉旧的镜像,包含非latest 和旧shortCommitHash 的镜像。

    5 replies  •  2021-05-25 15:52:11 +08:00
    Latin
    Latin
    May 25, 2021
    1
    主题应该是批量吧 没描述清楚意思
    Puteulanus
    Puteulanus
    May 25, 2021❤️1
    2
    https://github.com/andrey-pohilko/registry-cli
    https://github.com/ricardobranco777/clean_registry

    我们的 registry 用的这俩,自动删除超过 30 天的镜像
    Acoffice
    Acoffice
    May 25, 2021
    3
    ```bash
    docker image prune -a --filter "until=$(date +'%Y-%m-%dT%H:%M:%S' --date='-15 days')"

    ```
    ShareDuck
    ShareDuck
    May 25, 2021
    4
    我们用的仓库是 Harbor,到目前为止我们都没有删除过仓库里的旧镜像,镜像是分层存储的,占用空间不是很大。系统提供了垃圾清理功能,不知道是不是干这个的。
    eudore
    eudore
    May 25, 2021
    5
    写了一个小脚本,每个镜像保留最近 5 个 tag,其他都删除。
    About   ·   Help   ·   Advertise   ·   Blog   ·   API   ·   FAQ   ·   Privacy   ·   Solana   ·   2038 Online   Highest 6679   ·     Select Language
    创意工作者们的社区
    World is powered by solitude
    VERSION: 3.9.8.5 · 33ms · UTC 12:27 · PVG 20:27 · LAX 04:27 · JFK 07:27
    ♥ Do have faith in what you're doing.