Self-hosted Docker Registry with Cloudflare R2 (S3-compatible) as Backend

Windix Feng
1 min readNov 9, 2024

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:

Cloudflare R2 Documentation

Docker Registry Documentation (see Configuration & S3 storage driver section)

Sign up to discover human stories that deepen your understanding of the world.

Free

Distraction-free reading. No ads.

Organize your knowledge with lists and highlights.

Tell your story. Find your audience.

Membership

Read member-only stories

Support writers you read most

Earn money for your writing

Listen to audio narrations

Read offline with the Medium app

No responses yet

Write a response