Reputation: 1
My "problem" is when i run my ci on my remote docker machine, the gitlab-runner leaves the container that has been used there without to remove them. The other thing is that the project sources are also given when you show into the volumes folder.
Does someone has maybe ideas how i can change it, that the container and project sources will be deleted after ci-pipeline run?
Good Regards, cRUSH
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
This is my current configuration.
Upvotes: 0
Views: 2489
Reputation: 2192
Sometimes it is better to leave it there because it will leave the Docker building cache and next time the image is building it might be faster. However, in docker there is command docker system df
that tells you how much space docker consume on your machine.
If you want to delete everything (NOT CURRENTLY USED docker images, volumes, containers...) just clean your machine with
docker system prune --volumes --all --force
The ideal place where to put this command with gitlab-ci is in after_script
job:
script:
- docker build .
after_script:
- docker system prune --volumes --all --force
Upvotes: 1