代码之家  ›  专栏  ›  技术社区  ›  rasilvap

根据docker映像名称或存储库删除或修剪悬挂的docker映像筛选器

  •  0
  • rasilvap  · 技术社区  · 3 年前

    我有下一个场景:

    Repository                     TAG             IMAGE_ID       CREATED          SIZE
    
    registry.someRegistry.         latest          fa8767676       5 hours ago     119MB
    registry.someRegistry.         <none>          878787874       29 hours ago    119MB
    registry.someRegistry.         <none>          jkj7jjjk4       2 days ago      119MB
    registry.someRegistry.         <none>          d99090iii       3 days ago      119MB
    otherRegistries..              other Tags.     otherIds.       otherDates..    ...
    

    对于这个场景,我需要实现一个过程,删除标记为的所有docker图像 registry.someRegistry ,但不是标记为的 latest 。我必须从程序中调用此进程,所以我不知道ID。

    运行该过程后,结果应该是:

    Repository                     TAG             IMAGE_ID       CREATED          SIZE
    
    registry.someRegistry.         latest          fa8767676       5 hours ago     119MB
    otherRegistries..              other Tags.     otherIds.       otherDates..    ...
    

    我尝试了以下命令:

    docker rmi --force $(docker images -q 'registry.someRegistry' | uniq)
    

    但是此命令删除的所有docker映像 registry.someRegistry

    是否有可能添加另一个过滤器来排除带有最新标签的图像?

    我知道 docker image prune 删除所有悬挂的图像,但我只需要删除 registry.someRegistry.

    有什么想法吗?

    0 回复  |  直到 3 年前
        1
  •  0
  •   rasilvap    3 年前

    我要找的是一份关于文件的摘要 https://docs.docker.com/engine/reference/commandline/image_prune/

    prune命令支持用于过滤目的的label和until,所以我所做的是根据需要删除的图像标签进行过滤。

    我使用了下一个命令: docker image prune --force --filter='label=someLabel.image'

    为了知道我需要什么标签,我使用了以下命令:

    sudo docker inspect registry.someRegistry.
    

    最后我得到了我想要的结果。