Nexus Docker registry cleanup
How disk space on the Nexus Docker registry (docker-hosted, blob store default) is freed, and why deleting tags alone does nothing.
[[TOC]]
Background¶
In September 2026 docker-hosted had grown to 84 GB while only about 19 GB was live data. The nightly cleanup job had been deleting old tags the whole time, but no space came back. After the fix below, the first full run took the disk from 85 GB to 20 GB.
How Nexus frees Docker disk space¶
Deleting a tag removes the manifest only. The layers (blobs) it pointed to stay in the Nexus DB as normal assets, so the blob cleanup has nothing to remove. Space only comes back after all four steps, in this order, each one finished before the next starts:
flowchart TD
A[1. cleanup.py<br/>delete old tags + unreferenced manifests] --> B
B[2. Task: Docker - Delete unused manifests and images<br/>delete layer assets no manifest uses] --> C
C[3. Task: Cleanup unused docker blobs from nexus<br/>mark blobs deleted=true] --> D
D[4. Task: Compact blob store<br/>remove the files from disk]
| Step | What it frees | If skipped |
|---|---|---|
| 1. Script deletes tags/manifests | nothing on disk yet | old images stay |
| 2. Docker GC task | layer assets in the DB | step 3 finds nothing (this was the bug) |
| 3. Blob cleanup task | marks blobs as soft-deleted | step 4 finds nothing |
| 4. Compact blob store | the files on disk | disk usage doesn't change |
The CronJob¶
nexus/nexus-cleanup.yml in playtelly-iac: Secret + ConfigMap (cleanup.py) + CronJob nexus-docker-cleanup in namespace nexus, every day at 02:00, concurrencyPolicy: Forbid.
| Env var | Value | Meaning |
|---|---|---|
NAMESPACES |
playtelly,malaysia,hotel,jastv |
Registry path prefixes to clean. Add new sites here. ibc was removed on purpose: ibc-iac now pulls from playtelly/. |
NEXUS_URL |
http://nexus.nexus.svc.cluster.local:8082 |
Docker registry API (catalog, tags, manifests) |
NEXUS_API |
http://nexus.nexus.svc.cluster.local:8081 |
Nexus REST API (asset search, tasks) |
DOCKER_REPO |
docker-hosted |
Nexus repository |
DRY_RUN |
False in the CronJob (the script's own default is true) |
true prints what it would delete and skips the Nexus tasks |
TASK_TIMEOUT |
7200 (default) |
Seconds to wait for each Nexus task |
The job logs in with the nexus-cleanup-secret Secret in the same file (NEXUS_USER, NEXUS_PASSWORD). The values are not shown here: see Nexus users and access.
What the script keeps¶
| Image or tag | Kept? |
|---|---|
prod-vX.Y.Z release tags, and every other tag on the same digest (for example prod-<sha>) |
Always. Only tags matching exactly prod-vX.Y.Z count as releases. |
prod-latest, staging-latest, and any prod- or staging- tag on the same digest |
Yes |
prod-cache, staging-cache (buildx cache) |
Yes, never touched |
Any other prod-* or staging-* tag on an older digest |
Deleted |
A repository with no <prefix>-latest tag |
Skipped for that prefix: nothing is deleted |
cosign sha256-<digest>.sig, .att and .sbom tags whose image still has a live tag |
Yes |
| cosign tags whose image is gone | Deleted |
Release images are protected by digest, not by tag name. A tag that shares a digest with a release is kept even if it isn't latest, because deleting a manifest by digest would remove the release too.
What the script does, in order¶
For each repository, steps 1 and 2 run together, then step 3 runs for every repository, then step 4 runs once:
- Old tags. Find the digests of all
prod-vX.Y.Ztags and protect them. For each prefix (prod,staging), delete every<prefix>-*tag whose digest differs from<prefix>-latestand from the protected digests. A tag with no manifest digest is skipped. - Signature tags. Delete cosign
.sig,.attand.sbomtags whose image no longer has a live tag. If no live image is found for the repository, it skips this step to be safe. In a dry run, digests that step 1 would delete count as already gone. - Untagged manifests. Collect every tagged digest plus the platform manifests it references (amd64 and arm64 in a multi-arch index). Delete every other
sha256:manifest found through the Nexus asset search. - Nexus tasks (live mode only). Run the three tasks from the table above, in order. For each name it runs every task whose name contains that text (case-insensitive), so one compact task per blob store all run. It polls
/service/rest/v1/tasks/<id>until the task is no longerRUNNINGbefore starting the next one.
In a dry run it prints [DRY RUN] Would delete … and skips the Nexus tasks.
Release tags are the only long-lived images
The nightly job keeps prod-latest, staging-latest and every prod-vX.Y.Z. An untagged staging or prod-<sha> build disappears at the next 02:00 run, so tag and deploy a release the same day. See Version control and releases.
The Docker GC task is not in git¶
Docker - Delete unused manifests and images was created by hand in the Nexus UI (2026-10-01). It lives in the Nexus database, not in this repo. If Nexus is rebuilt or the task is deleted, the script logs [WARN] Task '...' not found and disk starts growing again.
To create it again: Settings → System → Tasks → Create task → Docker - Delete unused manifests and images
| Field | Value |
|---|---|
| Task name | Docker - Delete unused manifests and images (the script matches on this text) |
| Repository | docker-hosted |
| Deploy offset | 24 hours |
| Task frequency | Manual (the CronJob triggers it) |
The other two tasks (Cleanup unused docker blobs from nexus, Compact blob store) must also exist with names that contain that text.
Run it by hand¶
kubectl -n nexus create job --from=cronjob/nexus-docker-cleanup nexus-cleanup-manual
kubectl -n nexus logs -f job/nexus-cleanup-manual
The task steps can take a long time on a large store. Look for one [OK] Task '...' finished line per task.
Troubleshooting¶
| Symptom | Cause / check |
|---|---|
| Disk doesn't go down after the job | Check the log for the three finished lines, in order. Missing GC task → see above. Compact ran before blob cleanup finished → the old script didn't wait; make sure the current ConfigMap is applied. |
Task '...' not found |
Task deleted or renamed in the UI. Create it again. |
still running after 7200s, moving on |
Very large store. The next task will see partial results. Raise TASK_TIMEOUT or run the job again. |
| Registry returns 404 for a layer right after GC | Expected for a layer nothing uses any more. Not a sign of orphan files. |
Script exits No projects found |
Wrong credentials, or NAMESPACES doesn't match any repo in /v2/_catalog. |
| A site can't pull an old tag | It was deleted because it wasn't latest and wasn't a prod-vX.Y.Z release. Sites must use a release tag, and the GitOps repo must be up to date. |
| A signature check fails for an image that still exists | Check the log for DELETE sha256-….sig. The image had no live tag when the job ran. Re-sign it, or deploy a release tag. |
| A repository is never cleaned | It has no prod-latest or staging-latest tag, or its path doesn't start with a name in NAMESPACES. |
Related: Cloud Node Disk & Memory Cleanup (buildx cache on the GitLab node).