acr purge in container registry no longer works. What is correct way of batch cleanup of old images

Tom D 40 Reputation points
2025-10-30T10:55:49.48+00:00

We used to rely on the below task running daily. At some point it stopped running and failing with

/bin/sh: line 1: acr: command not found
2025/10/08 07:12:54 Container failed during run: acb_step_0. No retries remaining.
failed to run step ID: acb_step_0: exit status 127

is purge still supported?



```dockerfile
PURGE_CMD="acr purge \
 --filter '.*:master.*' --ago 5d --keep 10 --untagged && \
 acr purge --filter '.*:-prod.*' --ago 5d --keep 10 --untagged && \
 acr purge --filter '.*:app-prod.*' --ago 5d --keep 10 --untagged && \
 acr purge --filter '.*:release-v.*' --ago 5d --keep 15 --untagged"


az acr task update \
  --name "scheduledPurgeNonMasterTask" \
  --cmd "$PURGE_CMD" \
  --registry my-registry \
  --context /dev/null

Azure Container Registry
Azure Container Registry
An Azure service that provides a registry of Docker and Open Container Initiative images.
{count} votes

1 answer

Sort by: Most helpful
  1. Himanshu Shekhar 1,860 Reputation points Microsoft External Staff Moderator
    2025-11-03T17:10:05.41+00:00

    @Tom D

    Here we can suggest that the environment was updated by Azure it seems so removing the availability of the acr command unless you explicitly specify running the task with the correct container image that contains the acr-cli.

    To fix this when creating or updating ACR purge tasks we must let Azure use the official acr-cli container image, which has the acr binary installed and accessible during the task runtime.

    please create the task again using the official ACR CLI container image to ensure the acr command is available:

    PURGE_CMD="acr purge --filter '.*:master.*' --ago 5d --keep 10 --untagged && \

    acr purge --filter '.*:-prod.*' --ago 5d --keep 10 --untagged && \

    acr purge --filter '.*:app-prod.*' --ago 5d --keep 10 --untagged && \

    acr purge --filter '.*:release-v.*' --ago 5d --keep 15 --untagged"

    then , az acr task create \

    --name scheduledPurgeNonMasterTask \

    --registry myRegistry \

    --cmd "$PURGE_CMD" \

    --schedule "0 0 * * *" \

    --context /dev/null

    For purging tags and manifests in ACR using az acr run with acr purge: https://xtls-v4.hkg1.meaqua.org/en-us/azure/container-registry/container-registry-auto-purge

    For running an ACR task on a defined schedule : https://xtls-v4.hkg1.meaqua.org/en-us/azure/container-registry/container-registry-tasks-scheduled

    Try using an ACR task YAML file where you specify the image in the cmd step.

    Exit code 125 is Docker's error code for invalid command syntax, returned when Docker cannot parse the arguments being passed to the docker run command.

    So, when you use --image as an az acr task create parameter, the system tries to pass it directly to Docker's run command, which doesn't recognize it as a valid docker run option.

    Let's try creating a file named for e.g. acr-purge-task.yaml (https://xtls-v4.hkg1.meaqua.org/en-us/azure/container-registry/container-registry-tasks-reference-yaml#acr-taskyaml-file-format)

    YAML

    version: v1.1.0
    steps:
      - cmd: mcr.microsoft.com/acr/acr-cli:latest
        args:
          - /bin/sh
          - -c
          - |
            acr purge --filter '.*:master.*' --ago 5d --keep 10 --untagged && \
            acr purge --filter '.*:-prod.*' --ago 5d --keep 10 --untagged && \
            acr purge --filter '.*:app-prod.*' --ago 5d --keep 10 --untagged && \
            acr purge --filter '.*:release-v.*' --ago 5d --keep 15 --untagged
    
    
    

    Then create the task as below suggested:

    Bash

    az acr task create \
      --name "scheduledPurgeOldProductionTask" \
      --registry <registryname> \
      --file <yourfilename.yaml> \
      --context /dev/null \
      --schedule "0 0 * * *"
    

    After creating the task with the corrected syntax, test it:

    Bash

    az acr task run --name "scheduledPurgeOldProductionTask" --registry <registryname>
    

    for e.g tried and it works adding for ref

    User's image

    1 person found this answer helpful.
    0 comments No comments

Your answer

Answers can be marked as 'Accepted' by the question author and 'Recommended' by moderators, which helps users know the answer solved the author's problem.