GitLab Runner Garbage Collection
To release unused Docker containers, networks and images, it is possible to remove them completely with a simple command. Removing the unused resources frees up hard disk space.
Prerequisites
- GitLab Runner
- SSH access
Execute System Prune
To perform a Docker System Prune on the GitLab Runner, establish an SSH connection with your privileged SSH user. The Docker System Prune can then be executed with the following command:
sudo docker system prune [OPTIONS] Example:
sudo docker system prune -a -f --volumes Available options
| Option | Description |
|---|---|
-a, -all | Removes all unused containers, networks and images |
-f, --force | No reconfirmation required |
--volumes | Remove anonymous and unused volumes |
If the SSH command cannot be executed by your SSH user, please contact our support so that your user can be assigned the necessary rights. (Managed)
Empty Docker Build Cache
Each build of a Docker image consists of several steps (layers) - e.g. installing dependencies, copying files or configuration. Docker saves these layers in a cache so that only changed steps, for example, have to be executed again in future builds. This can be emptied with the following command:
sudo docker buildx prune -a -f Available options
| Option | Description |
|---|---|
-a, -all | Removes the entire unused Docker build cache |
-f, --force | No reconfirmation required |
Set up cronjob
If you want to set up the Docker System Prune as a cronjob that is executed automatically at the desired time, you can set up the cronjob in our Customer Center. Please use our help center article under Cronjobs.
Alternatively, a cronjob can be created on the GitLab Runner itself using crontab -e. You can use our standard configuration for this or alternatively edit it as you wish.
System Prune
0 0 * * * sudo docker system prune -a -f --volumes
┬ ┬ ┬ ┬ ┬
│ │ │ │ │
│ │ │ │ └──── Day of the week (0-7, Sunday is 0 or 7)
│ │ │ └────── Month (1-12)
│ │ └──────── Day (1-31)
│ └────────── Hour (0-23)
└──────────── Minute (0-59) You can then save the file and the cron job will be executed every night at 00:00 (UTC).
Docker Build Cache
0 0 * * * sudo docker buildx prune -a -f
┬ ┬ ┬ ┬ ┬
│ │ │ │ │
│ │ │ │ └──── Day of the week (0-7, Sunday is 0 or 7)
│ │ │ └────── Month (1-12)
│ │ └──────── Day (1-31)
│ └────────── Hour (0-23)
└──────────── Minute (0-59) Check hard disk space
If the Prune system does not free up enough memory, this is due to used data and files that are necessary for the operation of the Runner. If this is the case, we recommend enlarging the hard disk. See also: Enlarge hard disk