Tips

Cache Docker Hub Images with Azure Container Registry

Describes how to configure artifact cache in Azure Container Registry, map Docker Hub and GHCR images to a private ACR namespace, and pull them with the Docker…

Published

This post explains how to use ACR (Azure Container Registry) to cache images from Docker Hub and GitHub Container Registry.

Detailed steps #

  1. Sign in to the Azure portal
  2. Create a resource
  3. Search for Container Registry and create one
  4. For users in mainland China, East Asia (Hong Kong), Southeast Asia (Singapore), or Japan East are recommended; otherwise, choose any region as needed
  5. Open the Container Registry you created
  6. Expand Services on the left, then click Cache
  7. Create rule and configure the rule
    1. Rule name: dockerio
    2. Source: Docker Hub
    3. Repository path: docker.io/*
    4. New ACR repository namespace: dockerio/*
  8. Configure other sources as needed, for example ghcr.io/* -> ghcrio/*
  9. If you are using it within an Azure environment, or you can sign in with Azure CLI, for example az acr login, then you do not need to set up the Token below. Go directly to Access Control (IAM) and configure the permission (AcrPull)
  10. Expand Repository permissions on the left, then click Token
  11. Click Add. For Token (name), enter a name you can identify, and select _repositories_pull for Scope
  12. Click Actions to the right of password1 to generate a Token for use. It will also provide a command for signing in to ACR with the Docker client. Be sure to remember this password; after you close it, you will not be able to see it again

Image replacement #

After everything is configured and your Docker client has signed in, replace image names according to the rules you configured. For example, using the rules above:

  1. library/redis:6.2 -> xxxxx.azurecr.io/dockerio/library/redis:6.2
  2. tensorchord/pgvecto-rs:pg14-v0.2.0 -> xxxxx.azurecr.io/dockerio/tensorchord/pgvecto-rs:pg14-v0.2.0

References #

  1. Choose the Right Azure Region for You | Microsoft Azure
  2. Artifact cache in Azure Container Registry