Reputation: 31
I am running a GitLab runner in docker on my local system which creates a docker image of the repository and runs some tests. This is my gitlab-ci.yml
:
variables:
GIT_SUBMODULE_STRATEGY: recursive
stages:
- build
- test
build image:
stage: build
image: docker:20.10.16
services:
- docker:dind
script:
- docker login -u $CI_REGISTRY_USER -p $CI_REGISTRY_PASSWORD $CI_REGISTRY
- docker pull $CI_REGISTRY_IMAGE
- docker build --cache-from $CI_REGISTRY_IMAGE -t $CI_REGISTRY_IMAGE .
- docker push $CI_REGISTRY_IMAGE
run-tests:
stage: test
image: $CI_REGISTRY_IMAGE
script:
- source /app/venv/bin/activate && pytest .
The problem is that this leaves docker images with a "none" tag that end up occupying a lot of storage as you can see from the image.
How can I avoid this? Is there an option to add in gitlab-ci.yml
such that the container used is deleted after the last stage is completed?
Upvotes: 0
Views: 1460
Reputation: 999
I suggest clearing the docker cache as well as clearing old build images as per the official documentation.
/usr/share/gitlab-runner# ./clear-docker-cache
/usr/share/gitlab-runner# docker system prune
Upvotes: 2