Sign inSign up

zachbg/registry-cache

By zachbg

•Updated 6 months ago

Pull-through cache for Docker Hub - avoid rate limits and speed up pulls

Image
1

1.6K

zachbg/registry-cache repository overview

⁠Registry Cache

Pull-through cache for Docker Hub (and other registries). Avoid rate limits, speed up pulls, and save bandwidth across your cluster.

⁠Why?

Docker Hub enforces 100 pulls per 6 hours for anonymous users. In a CI/CD pipeline or Kubernetes cluster, you hit this limit constantly. A local cache means each image is pulled from Docker Hub once, then served locally forever.

Real impact:

  • CI pipelines stop failing with "429 Too Many Requests"
  • Image pulls go from seconds to milliseconds
  • Bandwidth drops 90%+ for repeated pulls
  • Works offline after first pull

⁠Quick Start

services:
  registry-cache:
    image: zachbg/registry-cache:latest
    restart: unless-stopped
    ports:
      - "5000:5000"
    volumes:
      - registry-data:/var/lib/registry
    environment:
      CACHE_SIZE: 50g
      CACHE_TTL: 168h

volumes:
  registry-data:

Then configure Docker daemon (/etc/docker/daemon.json):

{
  "registry-mirrors": ["http://localhost:5000"]
}

⁠Environment Variables

VariableDefaultDescription
REGISTRY_PROXY_REMOTEURLhttps://registry-1.docker.ioUpstream registry URL
CACHE_SIZE50gMaximum cache size
CACHE_TTL168hHow long to keep cached layers
DOCKER_HUB_USERDocker Hub username (for higher limits)
DOCKER_HUB_PASSWORDDocker Hub password/token
GC_ENABLEDtrueRun periodic garbage collection
GC_INTERVAL86400GC interval in seconds (default: 24h)

⁠Examples

⁠With Docker Hub auth (5000 pulls/hr)
environment:
  DOCKER_HUB_USER: myuser
  DOCKER_HUB_PASSWORD: dckr_pat_xxxxx
⁠Cache GitHub Container Registry
environment:
  REGISTRY_PROXY_REMOTEURL: https://ghcr.io
⁠Cache Quay.io
environment:
  REGISTRY_PROXY_REMOTEURL: https://quay.io
⁠Kubernetes DaemonSet
apiVersion: apps/v1
kind: DaemonSet
metadata:
  name: registry-cache
spec:
  selector:
    matchLabels:
      app: registry-cache
  template:
    metadata:
      labels:
        app: registry-cache
    spec:
      containers:
      - name: cache
        image: zachbg/registry-cache:latest
        ports:
        - containerPort: 5000
          hostPort: 5000
        volumeMounts:
        - name: cache-data
          mountPath: /var/lib/registry
      volumes:
      - name: cache-data
        hostPath:
          path: /var/cache/docker-registry

⁠Performance

ScenarioWithout CacheWith Cache
docker pull nginx (cold)2-5s2-5s (first time)
docker pull nginx (warm)2-5s<100ms
10 nodes pulling same image10 pulls from Hub1 pull from Hub
CI with 50 builds/hourRate limitedNever limited

Tag summary

Content type

Image

Digest

sha256:1fd98fd9b…

Size

10.4 MB

Last updated

6 months ago

docker pull zachbg/registry-cache