Docker pull-through cache: four ways to set one up
Serving developers since 2016 Founder-run, no venture capital MFA, SSO and audit log on every plan
Every feature on every plan, with unlimited users. 14 days free. No credit card required.
Start free trialStarting at $99/month billed annually.
A pull-through cache stores a copy of every image your machines pull. The next time a machine asks for that same image, it comes from your cache instead of Docker Hub.
What a pull-through cache is, and what it isn’t
- It only caches what you pull, not the whole registry. The first pull fetches the image from upstream and stores its layers. Later pulls of that image come from the cached copy.
- It’s for pulling only. Pushing your own images to a pull-through cache isn’t supported. Those need a registry of their own.
- One upstream at a time. When you run the open source registry as a cache, it only mirrors a single upstream registry.
1. The daemon way: a registry mirror
Docker Engine can send every Docker Hub pull to a mirror first. Add the mirror to /etc/docker/daemon.json, then reload Docker:
{ "registry-mirrors": ["https://mirror.example.com"]}Docker’s docs put two limits on whether this fits:
- Only Docker Hub can be mirrored this way. Pulls from
ghcr.io,quay.io, or a private registry still go straight to their registry. - The mirror URL has to be the root of a domain, with no path after the host.
On Kubernetes nodes running containerd, you configure a hosts.toml file per registry instead. Point containerd at the directory in /etc/containerd/config.toml (containerd 2.x):
version = 3
[plugins."io.containerd.cri.v1.images".registry] config_path = "/etc/containerd/certs.d"Then add /etc/containerd/certs.d/docker.io/hosts.toml:
server = "https://registry-1.docker.io"
[host."https://mirror.example.com"] capabilities = ["pull", "resolve"]On k3s, put the configuration in /etc/rancher/k3s/registries.yaml on every node that pulls images, then restart k3s on each node:
mirrors: docker.io: endpoint: - "https://mirror.example.com"2. Run your own: the registry image as a proxy
Give the open source registry an upstream, and it runs as a pull-through cache:
proxy: remoteurl: https://registry-1.docker.io username: your-docker-hub-user password: your-docker-hub-access-token ttl: 168hYou can also pass the same option as an environment variable at startup:
docker run -d --name hub-cache --restart always -p 5000:5000 \ -v hub-cache:/var/lib/registry \ -e REGISTRY_PROXY_REMOTEURL=https://registry-1.docker.io \ registry:3Running it yourself comes with a few responsibilities:
- One upstream per cache. GitHub Container Registry or Quay requires a second instance.
- TLS and a hostname. A daemon mirror is an
https://URL at the root of a domain. - Access. Once your Docker Hub credentials are in the config, anyone who can reach the cache can pull anything those credentials can see. Put authentication in front of it.
- Disk and cleanup. Old entries are only removed when
deleteis enabled in the registry’s storage settings. - The server itself. You own upgrades, monitoring, and the box it runs on.
3. The cloud’s: Amazon ECR pull through cache
In AWS, a pull through cache rule turns an ECR registry prefix into a cache for an upstream registry. Docker Hub needs its credentials stored in a Secrets Manager secret whose name starts with ecr-pullthroughcache/. Then pull with the prefix in the name, keeping library/ for official images:
docker pull 111122223333.dkr.ecr.us-east-1.amazonaws.com/docker-hub/library/alpine:3.22ECR checks the upstream for a newer image at least once every 24 hours. Every client signs in to ECR with AWS credentials, so it suits builds that already run in AWS.
4. The name way: pull from the cache by name
You can skip daemon configuration altogether. Put the cache address right in the image name, and any client that pulls images can use it: Docker, BuildKit, Podman, or Kubernetes.
FROM cache.example.com/docker-hub/library/alpine:3.22docker pull cache.example.com/docker-hub/library/alpine:3.22This works for every upstream the cache serves, not just Docker Hub. The cache address is also visible in the build file, so nobody has to remember a daemon setting on a new runner.
This is where CloudRepo helps
A CloudRepo Docker proxy repository is a pull-through cache we run for you in front of Docker Hub, GitHub Container Registry, Quay, Amazon ECR Public, or the Microsoft Container Registry. Store your Docker Hub sign-in in the proxy once, and Docker Hub counts its pulls against your account instead of as anonymous pulls. Your builds sign in to CloudRepo with one token without holding a Docker Hub secret, and the Access Log shows which token pulled what.
Docker’s own page explains how Docker Hub counts a signed-in account’s pulls, and what each plan allows: Docker Hub pull usage and limits.
echo "$CLOUDREPO_TOKEN" | docker login your-org.mycloudrepo.io --username you@example.com --password-stdindocker pull your-org.mycloudrepo.io/repositories/docker-hub/library/alpine:3.22More: Docker Hub rate limits, Proxy repositories and upstream sign-in, Official images by short name.
Every feature on every plan, with unlimited users
14 days free. No credit card required.
Starting at $99/month billed annually.
Founder-run since 2016, with no venture capital. A real person answers within one business day. Usually it's me.
Chris, founder of CloudRepo