Skip to content

Instantly share code, notes, and snippets.

@jk
Last active April 23, 2025 01:02
Show Gist options
  • Save jk/310736b91e9afee90fd0255c01a54d7d to your computer and use it in GitHub Desktop.
Save jk/310736b91e9afee90fd0255c01a54d7d to your computer and use it in GitHub Desktop.
Use an internal

To use your internal docker hub pull cache, you need to change the config of your docker clients.

In /etc/daemon.json:

{
    "registry-mirrors": [
        "https://dockerhub-cache.example.tld"
    ]
}

Caveat

From time to time, the proxy chokes on its own storage. That's why we throw away the storage over the weekend and restart the proxy automatically. Run the purge-cache.sh via cron.

version: 0.1
proxy:
remoteurl: https://registry-1.docker.io
username: [your dockerhub user]
password: [your dockerhub password]
delete:
enabled: true
storage:
delete:
enabled: true
cache:
blobdescriptor: inmemory
filesystem:
rootdirectory: /var/lib/registry
maxthreads: 100
cache:
blobdescriptor: inmemory
log:
formatter: text
fields:
service: registry
http:
addr: 0.0.0.0:443
headers:
X-Content-Type-Options: [nosniff]
Access-Control-Allow-Origin: ['*']
secret: verySecret
tls:
certificate: /etc/ssl/server.crt
key: /etc/ssl/server.key
debug:
addr: 0.0.0.0:5001
prometheus:
enabled: true
path: /metrics
version: '3.9'
services:
cache:
image: registry:2.8.3
restart: unless-stopped
hostname: dockerhub-cache.example.tld
ports:
- 443:443 # actual port for the docker clients
- 5001:5001 # prometheus metrics
volumes:
- ./config.yml:/etc/docker/registry/config.yml:ro
- ./server.chain.crt:/etc/ssl/server.crt:ro
- ./server.key:/etc/ssl/server.key:ro
- ./storage:/var/lib/registry:rw
#!/usr/bin/env bash
set -euo pipefail
# Check if the script is running with root privileges
if [ "$(id -u)" -ne 0 ]; then
echo "This script must be run with sudo or as root." >&2
exit 1
fi
# Get the directory path of the script
script_dir=$(dirname "$0")
# Change the current working directory to the script's directory
cd "$script_dir"
# Run commands from within the script's directory
echo "Current working directory: $(pwd)"
STORAGE_DIR=storage
echo "Remove recursivly ${STORAGE_DIR} directory ..."
docker compose down
rm -Rfv $STORAGE_DIR | pv -l -s $( sudo du -a $STORAGE_DIR | wc -l ) > /dev/null
docker compose up -d --force-recreate
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment