我的“问题”是,当我在远程docker机器上运行ci时,gitlab-runner离开了曾经使用过的容器,而没有删除它们。另一件事是,当您显示到volumes文件夹中时,也会提供项目源。
有人可能会想到我该如何更改它,即在ci-pipeline运行后删除容器和项目源吗?
良好的问候, 粉碎
stages:
- Build
- Testing
- Execute
- Publish
- CleanUp
build_cleanup:
only:
- master
stage: Build
script:
- "dotnet clean"
- (if [ $(docker ps -a | grep $CONTAINER_NAME | cut -d " " -f1) ]; then echo $(docker rm -f $CONTAINER_NAME); else echo OK; fi;);
- (if [ $(docker volume ls -qf dangling=true) ]; then echo $(docker volume prune -f); else echo OK; fi;);
when: on_failure
testing_cleanup:
only:
- master
stage: Testing
script:
- "dotnet clean"
- (if [ $(docker ps -a | grep $CONTAINER_NAME | cut -d " " -f1) ]; then echo $(docker rm -f $CONTAINER_NAME); else echo OK; fi;);
- (if [ $(docker volume ls -qf dangling=true) ]; then echo $(docker volume prune -f); else echo OK; fi;);
when: on_failure
excecute_cleanup:
only:
- master
stage: Execute
script:
- "dotnet clean"
- (if [ $(docker ps -a | grep $CONTAINER_NAME | cut -d " " -f1) ]; then echo $(docker rm -f $CONTAINER_NAME); else echo OK; fi;);
- (if [ $(docker volume ls -qf dangling=true) ]; then echo $(docker volume prune -f); else echo OK; fi;);
when: on_failure
publish_cleanup:
only:
- master
stage: Publish
script:
- "dotnet clean"
- (if [ $(docker ps -a | grep $CONTAINER_NAME | cut -d " " -f1) ]; then echo $(docker rm -f $CONTAINER_NAME); else echo OK; fi;);
- (if [ $(docker volume ls -qf dangling=true) ]; then echo $(docker volume prune -f); else echo OK; fi;);
when: on_failure
cleanup_jobs:
only:
- master
stage: CleanUp
script:
- "dotnet clean"
- (if [ $(docker ps -a | grep $CONTAINER_NAME | cut -d " " -f1) ]; then echo $(docker rm -f $CONTAINER_NAME); else echo OK; fi;);
- (if [ $(docker volume ls -qf dangling=true) ]; then echo $(docker volume prune -f); else echo OK; fi;);
when: always
这是我当前的配置。
答案 0 :(得分:0)
有时最好将其保留在那里,因为它将离开Docker构建缓存,而下次构建映像时,它可能会更快。但是,泊坞窗中有命令docker system df
,该命令告诉您泊坞窗在您的计算机上消耗了多少空间。
如果要删除所有内容(当前未使用 Docker映像,卷,容器...),只需使用
清洁计算机即可。docker system prune --volumes --all --force
使用gitlab-ci放置此命令的理想位置是after_script
job:
script:
- docker build .
after_script:
- docker system prune --volumes --all --force