Self-hosted Docker Registry with Cloudflare R2 (S3-compatible) as Backend
Cloudflare R2 is an S3-compatible object storage with 10GB / month free storage for free tier.
Assume you have created bucket and API access already in Cloudflare R2.
config file (/data/appdata/docker-registry-s3/config.yml
):
version: 0.1
log:
accesslog:
disabled: false
level: info
fields:
service: registry
storage:
cache:
blobdescriptor: inmemory
# filesystem:
# rootdirectory: /var/lib/registry
s3:
accesskey: UPDATE-ME
secretkey: UPDATE-ME
region: apac
forcepathstyle: true
regionendpoint: https://UPDATE-ME.r2.cloudflarestorage.com
bucket: docker-registry
chunksize: 104857600
multipartcopychunksize: 33554432
multipartcopymaxconcurrency: 100
multipartcopythresholdsize: 33554432
# rootdirectory: /s3/object/name/prefix
http:
addr: :5000
headers:
X-Content-Type-Options: [nosniff]
# health:
# storagedriver:
# enabled: true
# interval: 10s
# threshold: 3
If you saw this error in the logs “unknown error completing upload: InvalidPart: All non-trailing parts must have the same length.”, it can be fixed by updating chunksize
setting above (already updated).
source: https://community.cloudflare.com/t/all-non-trailing-parts-must-have-the-same-length/552190/8
docker command:
docker run -d
-p 5000:5000 \
--restart=always \
--name docker-registry-s3 \
-v /data/appdata/docker-registry-s3/config.yml:/etc/docker/registry/config.yml \
registry:2
For troubleshooting:
To use aws-cli
with Cloudflare R2:
export AWS_ACCESS_KEY_ID=UPDATE-ME
export AWS_SECRET_ACCESS_KEY=UPDATE-ME
export AWS_ENDPOINT_URL=https://UPDATE-ME.r2.cloudflarestorage.com
aws s3 ls s3://docker-registry
To check if your registry is running correctly: visiting http://localhost:5000/v2/_catalog
and you should see JSON payload list all your repositories.
The default path strcture for registry in s3 bucket is: /docker/registry/v2/{blobs,repositories}
Reference Links:
Docker Registry Documentation (see Configuration & S3 storage driver section)