Secure and Streamline: Automate the Cleanup of Container Images Across AWS, Azure, and GCP

Container images are constantly being built, pushed, and deployed. Whether you’re running on Amazon Web Services (AWS), Microsoft Azure, or Google Cloud Platform (GCP), your container registries can quickly become cluttered with outdated, unused, and even vulnerable images.

Old and unused container images increase your attack surface by exposing vulnerable software that’s no longer maintained. They inflate costs through unnecessary storage, slow down vulnerability scanners, and generate noise in your security tools. These images often trigger alerts for components no longer in use, leading to confusion and wasted time during incident response or audits. All of this creates mass friction for security and DevOps teams, forcing them to constantly ask: “Do we still need this image?”, “Where is it used?”, and “Why is it still here?”

The solution? Automated lifecycle management and each major cloud provider offers a way to automatically clean up stale or untagged images in your container registries.

Let’s explore how Amazon ECR, Azure Container Registry, and Google Artifact Registry help you reduce risk, save money, and streamline container security with lifecycle policies.

Why You Should Care About Image Cleanup

Across all clouds, unused images can pose security and operational risks:

  • Vulnerability exposure: Even if an image is no longer deployed, if it contains known CVEs, it still represents a potential security risk, especially if mistakenly reused or exposed.
  • Alert fatigue: Many security tools scan entire registries and don’t distinguish between active and inactive images. This leads to findings from old versions even after you’ve deployed a fixed image. These tools often don’t connect the old vulnerable image with the new, secure one, which clutters dashboards and delays triage.
  • Storage and cost bloat: Container images can be large. Storing dozens (or hundreds) of unused versions means higher cloud bills.
  • Policy and compliance pressure: Many frameworks and standards require proper asset lifecycle management including containers.

Automated Image Cleanup by Cloud Provider

Amazon ECR (Elastic Container Registry)

Amazon ECR supports lifecycle policies that automatically delete images based on age, tag status, and count.

Example: Expire untagged images after 14 days

				
					{
  "rules": [
    {
      "rulePriority": 1,
      "description": "Expire untagged images older than 14 days",
      "selection": {
        "tagStatus": "untagged",
        "countType": "sinceImagePushed",
        "countUnit": "days",
        "countNumber": 14
      },
      "action": {
        "type": "expire"
      }
    }
  ]
}

				
			

You can simulate the outcome using:

				
					aws ecr start-lifecycle-policy-preview --repository-name my-repo
				
			

Azure Container Registry (ACR)

Azure provides ACR Tasks and retention policies to automatically delete untagged or stale images.

Example: Delete untagged images older than 30 days

				
					az acr config retention update --name myRegistry --resource-group myResourceGroup \
  --status enabled --days 30 --type UntaggedManifests
				
			

Note: More advanced lifecycle logic (like by tag pattern or image count) may require custom scripting or Azure Container Registry Tasks.

Google Artifact Registry (and GCR)

GCP’s Artifact Registry supports cleanup policies to manage stale images.

Example: Retain only images less than 30 days old

				
					gcloud artifacts repositories update REPO_NAME \ 
--location=LOCATION \
--cleanup-policy=AGE >30d
				
			

Policies can be defined using YAML, Terraform, or gcloud CLI. You can retain the latest N images or delete those older than a specific threshold.

Security Best Practices Across all Providers

Regardless of your cloud provider, these best practices apply:

  • Adopt a consistent image tagging strategy. Use semantic versioning and avoid relying solely on the latest.
  • Delete untagged and unused images regularly. Limit image retention by age or count to reduce registry size and risk.
  • Integrate cleanup with vulnerability scanning. Ensure only images in active use are scanned & alerted on.
  • Monitor and audit cleanup actions via logging tools like AWS CloudTrail, Azure Monitor, or GCP Audit Logs.

Bonus Points - Open Source Tools

Want to further level up? Let’s talk open source.

Automating cleanup and lifecycle management across AWS, Azure, and GCP is essential, but for complete visibility and enhanced security, leveraging the right open-source tools provides even more depth and control. 

Here are some proven open-source solutions that perfectly complement automated registry cleanup:

1. Syft

Syft generates Software Bill of Materials (SBOM) for your container images. An SBOM provides detailed insights into the exact contents, dependencies, and software components within an image.

Why it’s recommended:

  • Essential for supply chain security.
  • Helps ensure compliance with regulatory frameworks by clearly outlining software components.
  • Enables rapid vulnerability assessment when new CVEs are disclosed.

2. Grype

Grype scans container images and generates detailed vulnerability reports directly from SBOMs produced by tools like Syft. It identifies CVEs, outdated libraries, and vulnerable software versions embedded in your containers.

Why it’s recommended:

  • Provides precise vulnerability insights tailored specifically to your container’s contents.
  • Reduces false positives by leveraging detailed SBOM data.
  • Ideal for integration into CI/CD pipelines to shift security left.

3. Trivy

Trivy is a versatile vulnerability scanner known for its speed, accuracy, and ease of use. It scans container images, file systems, and even Infrastructure as Code (IaC) files, highlighting outdated or vulnerable packages.

Why it’s recommended:

  • Comprehensive detection of vulnerabilities across multiple layers.
  • Easily integrates into automated workflows, providing fast feedback loops.
  • Lightweight and efficient, minimizing impact on build and deployment speeds.

4. Dive

Dive analyzes container image layers, identifying inefficient use of storage, redundant files, and unnecessary bloat. It visualizes each image layer, allowing you to optimize storage usage proactively.

Why it’s recommended:

  • Significantly reduces image size, resulting in cost savings.
  • Provides insights into best practices for image layering and optimization.
  • Enhances performance by ensuring only necessary components are packaged in your containers.

5. Harbor

Harbor is a powerful open-source container registry that integrates seamlessly with Clair or Trivy for built-in vulnerability scanning. It also offers robust features such as RBAC, policy-driven image retention, and automated replication.

Why it’s recommended:

  • Centralizes container image management and security in one user-friendly interface.
  • Facilitates policy-driven lifecycle management and retention.
  • Supports secure image signing and validation, adding another layer of protection.

Using these open-source tools in combination with cloud-native automated cleanup policies will allow you to maintain a lean, secure, and compliant container environment. You’ll gain deeper visibility into your containers, proactively manage vulnerabilities, optimize resource use, and enhance your overall cloud security posture. Don’t just clean your registries—understand and secure every image within them.

Final Thoughts

Managing container image sprawl isn’t just about saving storage, it’s a key security practice. Every cloud provider, AWS, Azure, and GCP, gives you the tools to automate image cleanup, reduce alert noise, cut costs, and shrink your attack surface.
Automating container image lifecycle policies helps you:

  • Stay compliant
  • Reduce false positives in security tools
  • Respond faster to real threats
  • Keep your environment clean and production-ready

Don’t let old containers live forever, automate your cleanup, secure your registry, and shift security left. 

To learn how ZEST help remediate and mitigate container vulnerabilities and other risks and exposure, schedule a meeting with our team

Share the Post:

Related Resources

Secure and Streamline: Automate the Cleanup of Container Images Across AWS, Azure, and GCP

Container images are constantly being built, pushed, and deployed. Whether…

Cloud Under Siege: 6 Cloud Breaches and Leaks in Spring 2025

The hits keep coming – from surveillance apps leaking plaintext…

Thousands of organizations at risk by Salesforce Industry Cloud bugs

Snir Ben Shimol, co-founder and CEO of Zest Security, said…

ZEST Security Integrates with Upwind

ZEST Security announced its strategic integration with Upwind combining runtime…

From Managing to Resolving: Transforming Vulnerability Management for Cloud

ZEST Security partners with Upwind for faster AI-driven cloud fixes

ZEST Security has announced a new integration with Upwind to…

ZEST Security and Upwind Partner to Close the Gap Between Cloud Threat Detection and Action

ZEST Security and Upwind have launched a new integration that…

Runtime Visibility Meets Intelligent Remediation: ZEST + Upwind

The complexity of cloud environments and modern applications demands specialized,…

How Malicious AWS Lambda Layers Can Compromise Your Serverless Environment

AWS Lambda Layers are a powerful feature that enables developers…

RSA Conference 2025 – Pre-Event Announcements Summary

ZEST Security announced the launch of its Multi-Agent AI System,…

ZEST AI Agents: Risk Remediation, Reimagined

Risk remediation is broken. Security teams are overwhelmed, drowning in…

ZEST Security Unveils Multi-Agent AI System to Autonomously Remediate and Mitigate Cloud Risks at RSAC 2025

NEW YORK/RSAC, April 22, 2025 – ZEST Security, provider of…

AWS Organizations and Delegated Administrator: Security Pros and Cons

Introduction AWS Organizations is a service that enables centralized governance…

ZEST for Cloud Security Risk Resolution

How ZEST streamlines remediation and mitigation of cloud security risks…

7 RSAC 2025 Cloud Security Sessions You Don’t Want to Miss

Some of the brightest minds in the industry will discuss…

Understanding Preemptive Exposure Management and Why it Matters

Last week, Gartner® released a new emerging technology report on…

ZEST Platform Now Available in AWS Marketplace

We are excited to announce that ZEST Security’s Agentic-AI Risk…

How to go From Zero to a Well-Secured, Managed Cloud Security State

Building an effective cloud security risk management program can seem…

Google’s $32 Billion Wiz Buy Bolsters Its Cloud Security Capabilities, Experts Say

Google Cloud aims to harness Wiz’s expertise and Mandiant’s threat…

Aaron Brown Joins ZEST Security’s Advisory Board

Today we are excited to officially announce that Aaron Brown,…

$32 billion Google-Wiz deal bodes well for cloud security, experts say

Cloud industry leaders such as Snir Ben Shimol, co-founder and…

Building a Cloud Security Program That Actually Works

In this webinar, we discuss essential best practices and milestones…

Code to Cloud and Back: Closing the Remediation Loop

What is Code to Cloud? Everyone is in the cloud,…

The Future of Cloud Security and the Role of AI

With the visibility challenge largely addressed, what’s next? How will…

ZEST Security’s Cloud Risk Exposure Impact Report Reveals 62% of Incidents are Related to Risks Known to the Organization

ZEST Security, provider of an Agentic-AI Cloud Risk Resolution platform,…

4 Reasons Cloud Security Risk Management is Adopting an Incident Response Mentality

The high volume of alerts, combined with tedious and manual…

Stat of the week

Cybersecurity professionals have to always have one eye on the…

Cloud security report shows growing remediation gap amid increased risk awareness

Attackers now exploit vulnerabilities within an average of five days,…

Beyond CVSS: Why EPSS and KEV Are Game-Changers for Prioritizing Vulnerabilities

Publicly disclosed computer vulnerabilities are organized into a globally recognized…

Cloud risks rise due to slow remediation, costs USD $2m+

The study reports that organisations face an annual remediation cost…

Resolving your cloud risks with ZEST!

Zest Logo

“62% of Incidents are Related to Risks Known to the Organization”