gitlab-runner的Docker卷清理

我是 docker 和 jenkins 的新手。但是最终我在 jenkins 中创建了一个作业,以便我可以删除存储在我们的 linux 机器(CentOS7)中的 gitlab-runner 的卷缓存

为了实现这一点,我每 6 小时在 jenkins 中使用以下命令创建一个定期作业:

docker volume prune -f 

但是它根本不清理空间。这是詹金斯工作的输出:

Started by timer
Running as SYSTEM
Building remotely on buildbng17 (gitlab) in workspace /mnt/data0/jenkins/workspace/gitlab-cleanup
[WS-CLEANUP] Deleting project workspace...
[WS-CLEANUP] Deferred wipeout is used...
[WS-CLEANUP] Done
[gitlab-cleanup] $ /bin/sh -xe /tmp/jenkins3799570002967825583.sh
+ find /mnt/data0/gitlab/data/backups/ -name '*.tgz' -mtime +30
/mnt/data0/gitlab/data/backups/etc-gitlab-1611415968.tgz
Started calculate disk usage of build
Finished Calculation of disk usage of build in 0 seconds
Started calculate disk usage of workspace
Finished Calculation of disk usage of workspace in 0 seconds
Finished: SUCCESS

当我去我的 buildbng17 机器并检查他们是否有任何音量时,所以我必须通过执行来清理音量

docker volume prune

唯一的缺点是我需要手动完成并在要求确认时给出“y”。并且数据变得干净。

我应该在 jenkins 中给出什么命令,以便它在不要求确认的情况下自动清理卷?(因为 docker volume prune -f 不起作用)

我什至尝试在我的 linux 机器上手动运行 docker volume prune -f 命令,它仍然没有清理卷并显示 0kb 已释放(但是我从 docker volume ls 检查了卷)

我们有什么更好的方法可以在 gitlab-runner 内部自动执行它吗?或者我不知道的 jenkins 或 docker 的一些更好的功能?

gitlab-runner 继续运行并覆盖磁盘空间。

还有一件事:我们在 docker 上使用 Gitlab 和 Gitlab-runner。

提前致谢,萨米尔

回答

运行以下命令进行清理:

# Remove exited containers
docker ps -a -q -f status=exited | xargs --no-run-if-empty docker rm -v

# Remove dangling images
docker images -f "dangling=true" -q | xargs --no-run-if-empty docker rmi

# Remove unused images
docker images | awk '/ago/  { print $3}' | xargs --no-run-if-empty docker rmi

# Remove dangling volumes
docker volume ls -qf dangling=true | xargs --no-run-if-empty docker volume rm


以上是gitlab-runner的Docker卷清理的全部内容。
THE END
分享
二维码
< <上一篇
下一篇>>