Build Cache占用磁盘太多

avatar 2023年11月5日18:13:34 评论 236 次浏览

在jenkins环境中,经常发版所以会有很多docker build的操作,时间久了,就会发生镜像构建过程中缓存会越来越多,长久下去,就会发生磁盘满的情况,下面看一下我是如何操作的。

 [wolf@wulaoer.org 🔥🔥🔥🔥 ~ ]$ docker system df
 TYPE            TOTAL     ACTIVE    SIZE      RECLAIMABLE
 Images          9         2         3.815GB   3.231GB (84%)
 Containers      2         2         0B        0B
 Local Volumes   2         2         4.587MB   0B (0%)
 Build Cache     1772      0         52.98GB   52.98GB

我现在缓存已经有五十多G了,目前的镜像不能删除,而且还有一些容器也需要继续使用,只能清理Build Cache,如果使用docker system prune会把删除关闭的容器、无用的数据卷和网络,以及dangling镜像(即无tag的镜像)都会删除,如果使用docker system prune -a清理掉更测地,会把所有的docker镜像都删除掉。

这里我们可以使用docker builder prune,会把所有的缓存都清理掉。

 [wolf@wulaoer.org 🔥🔥🔥🔥 ~ ]$ docker builder prune
 WARNING! This will remove all dangling build cache. Are you sure you want to continue? [y/N] y
 ID            RECLAIMABLE SIZE    LAST ACCESSED
 ...............................................
 [wolf@wulaoer.org 🔥🔥🔥🔥 ~ ]$ docker system df
 TYPE            TOTAL     ACTIVE    SIZE      RECLAIMABLE
 Images          9         2         3.815GB   3.231GB (84%)
 Containers      2         2         0B        0B
 Local Volumes   2         2         4.587MB   0B (0%)
 Build Cache     57        0         0B        0B

清理完了,如果想保留一部分可以使用--filter参数,比如保留十天。

 [wolf@wulaoer.org 🔥🔥🔥🔥 ~ ]$ docker builder prune --filter 'until=240h'

后期就可以做一个定时任务,经常跑一下就可以了,没有了,看些其他的吧。

avatar

发表评论

:?: :razz: :sad: :evil: :!: :smile: :oops: :grin: :eek: :shock: :???: :cool: :lol: :mad: :twisted: :roll: :wink: :idea: :arrow: :neutral: :cry: :mrgreen: