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

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

  •  
  •   JasonLaw · May 25, 2021 · 2154 views
    This topic created in 1850 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
        1
    Latin  
       May 25, 2021
    主题应该是批量吧 没描述清楚意思
    Puteulanus
        2
    Puteulanus  
       May 25, 2021   ❤️ 1
    https://github.com/andrey-pohilko/registry-cli
    https://github.com/ricardobranco777/clean_registry

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

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