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 untagged manifests 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 with the corresponding user name in the following command.


0 0 * * * * <username-of-system-user> sudo gitlab-ctl registry-garbage-collect -m