GitLab Garbage Collection
The GitLab Container Registry can take up a considerable amount of disk space on your GitLab server. To effectively free up the disk space consumed by the container registry, GitLab includes a garbage collector. With the garbage collector, unreferenced image layers as well as manifests without tags can be removed fully automatically.
Perform garbage collection manually
Remove unreferenced layers
Image layers make up the largest part of the storage space in the container registry. An image is considered unreferenced if no image manifest refers to it. Unreferenced layers are the default target of the container registry's garbage collector.
sudo gitlab-ctl registry-garbage-collect
Remove untagged manifests and unreferenced layers
By default, the garbage collector of the container registry ignores unlabeled images. To remove unlabeled images via garbage collection, the parameter -m
can be added to the command.
sudo gitlab-ctl registry-garbage-collect -m
Set up garbage collection fully automatically via cronjob
To have the garbage collection performed fully automatically via a time-controlled task, you can store a corresponding cron job for your system user on your GitLab server.
Open Cronjob Editor
crontab -e
Create cronjob for fully automatic garbage collection
With the following cronjob the garbage collection is carried out daily at 0.00 o'clock.
Please replace
Since the Crontab service does not have a bash environment, the absolute path to the binary /usr/bin/gitlab-ctl
must be specified in the cronjob instead of gitlab-ctl
.
0 0 * * * * sudo /usr/bin/gitlab-ctl registry-garbage-collect -m 2>&1 | /usr/bin/logger -t GITLAB
Check logs:
journalctl -f -t GITLAB