exitista
exitista

Reputation: 583

Know number of images in Azure Container Registry

Im new to Azure Container Registry. How can I know the number of images per repository? It is possible by Portal? And also I want to know to do it by command-line

Upvotes: 0

Views: 2134

Answers (2)

audunsol
audunsol

Reputation: 448

Just stumbled across this in search of a tool to figure out my biggest repos, and thought I could extend @charles-xu's answer, to actually get the number of manifests and images per repository from the command line (bash):

FILE='repolist.json'
ACRNAME='MyACR'

# Remove file if it exists, to avoid
# appending to a potentially existing file:
rm -f $FILE

az acr repository list -n $ACRNAME \
  | jq -r '.[]' \
  | while read repo; do
      echo -n "Processing ${repo}..."
      # Get details for each repo, and compact the JSON to 1 line with jq -c: 
      az acr repository show -n $ACRNAME --repository $repo \
        | jq -c . >> $FILE
      echo " Done."
    done

# Clean up file by slurping each row into a proper JSON array,
# and write back to same file inline using cat:
cat <<< $(jq -s . $FILE) > $FILE

Not very performant (doing one network call to get details per repository sequentally), but it did the job for me now.

From here you can do whatever you want with the output JSON file. Continuing on the command line, here is an example of getting a nicely structured table of the top 10 repositories with most tags utilizing the nice rich-cli tool:

jq 'sort_by(.tagCount)|reverse' $FILE \
 | jq -r '.[]|[.imageName, .manifestCount, .tagCount]| @csv' \
 | head -n 10 \
 | rich --csv -

Upvotes: 0

Charles Xu
Charles Xu

Reputation: 31424

Well, I will show you something to you to understand what is the difference between the image tag and the repository.

When you create an image, it must have a tag, then you push the image with the tag to Azure Container Registry. This time, there will be a repository with the name of your image to store the image manifest and tag.

Here will be two conditions:

  1. If you update the image with a new tag and do not change the image name, then you push it to Azure Container Registry. The image will still store in the old repository with the new tag. Now your Azure Container Registry has one repository with two tags for the image.
  2. If you update the image with a new tag or still the old one and change the image name, then you push it to Azure Container Registry. It will create a new repository to store the image with the new name. Now you have two repositories, and each one has a tag for the image.

Now, come back to your question:

How can I know the number of images per repository?

If you want to know the number of the images in the same repository, you just need to calculate the number of the tags.

If you want to know the number of the image with different names, you need to calculate the number of repositories.

There is no Azure command to get the number of the images directly, you need to do it yourself. For example, use Azure CLI in bash:

az acr repository list -n yourACR | wc -l

This command will show you a number, but it's not the real number of the repositories. You need to subtract 2. Hope it helps :-)

Upvotes: 2

Related Questions