Skip to content

Instantly share code, notes, and snippets.

@philippschmalen
Last active July 16, 2026 11:30
Show Gist options
  • Select an option

  • Save philippschmalen/2eef8f23a5069e49d021fb30918673b9 to your computer and use it in GitHub Desktop.

Select an option

Save philippschmalen/2eef8f23a5069e49d021fb30918673b9 to your computer and use it in GitHub Desktop.
Azure Container Registry - Daily purge storage optimization

Azure Container Registry - Daily purge storage optimization

Reduce storage and costs by removing docker images that are not needed anymore.

Prerequisites

  1. az cli installed
  2. successfully authenticated

Example

Purge all images except for stage and master daily at midnight.

#!/bin/bash

set -euo pipefail
  

REGISTRY=<registry-name>

# filter images by tags that can be removed
# example: remove all images except for `stage` and `master`
PURGE_CMD="acr purge --filter '.*:^(?!^stage\$|^master\$).*\$' --untagged --ago 0d"

az acr task create \
  --name "daily-purge" \
  --registry "$REGISTRY" \
  --cmd "$PURGE_CMD" \
  --schedule "0 0 * * *" \
  --context /dev/null
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment