Course contentsShow
← Cloud and Infrastructure
Lesson 998 of 2,98919. Container FundamentalsFree lesson

Image Retention and Cleanup Policies

Managing registry storage with lifecycle policies to automatically remove old, unused, or untagged images.

Image Retention and Cleanup Policies

What you'll learn: How to automatically delete old or unused container images from your registry to save storage and reduce clutter.

Why Cleanup Matters

Container registries accumulate images quickly. Every build, every tag, every experiment adds data. Without management, registries become digital landfills—bloated with obsolete images that consume storage and slow searches. Think of it like a photo library: if you never delete duplicates or bad shots, finding the good ones becomes impossible.

What Are Lifecycle Policies?

Lifecycle policies are automated rules that define when and which images should be removed from your registry. Instead of manually hunting down old images, you set criteria, and the registry enforces them automatically.

Common policy triggers include:

  • Age: Remove images older than 90 days
  • Tag status: Delete untagged images (dangling layers from overwrites)
  • Keep count: Retain only the latest 10 versions of each image
  • Inactivity: Remove images not pulled in 6 months

How Policies Work

You configure policies using registry-specific syntax (YAML, JSON, or UI forms). The registry evaluates images against your rules on a schedule—often daily—and marks matches for deletion. Some registries offer dry-run modes to preview what would be deleted before executing.

Example scenario: You push a new image daily. A policy keeps the 30 most recent tagged versions and deletes anything untagged after 7 days. This balances rollback capability with storage efficiency.

Storage Impact

Removing image manifests doesn't always free space immediately. Remember: images share layers. A policy deletes the manifest (recipe), but underlying layers persist if other images reference them. Registries typically run garbage collection separately to reclaim orphaned layers.

Key Takeaway: Image retention and cleanup policies automate registry hygiene by removing old, unused, or untagged images based on rules you define—essential for controlling storage costs and maintaining registry performance.