remrin

remrin

github
email

Using Cloudflare Workers to Build Your Own Docker Image Source

A few days ago, all major mirror sites went down, making it a problem to pull Docker images.

At first, I didn't care; when it was down, I just used a proxy to pull, but even with a proxy, I couldn't pull normally when using Docker locally.

So I started looking for solutions, and after some research, I found the following options:

  • Build using Cloudflare Workers, which requires a domain -> Original post
  • Self-host Nexus 3, which requires a foreign VPS, preferably with 4GB RAM or more, and also requires a domain -> Original post
  • Use Github Action to transfer DockerHub images to Alibaba Cloud's private repository, which only requires a Github account -> Original post
  • Use Nginx reverse proxy, which is more suitable for those who already have a server -> Original post
  • Other options include finding existing image sources, but these are generally not very stable, so I didn't consider this.

I used the first option, which is relatively simple. The tutorial in the original post is not very detailed, so I'll elaborate here.

  1. Go to the Cloudflare homepage, create a new Worker in the left Workers & Pages section, and save the Account ID on the right. image

Give the Worker a name, click Save, and then click Finish.
image
When this page appears, you can proceed to the next step.
image

  1. Fork this repository and Clone it to your local machine.

As usual, install the dependencies first.

pnpm i

Then rename wrangler.toml.sample to wrangler.toml.

cp wrangler.toml.sample wrangler.toml

Edit the wrangler.toml file, modifying name and account_id.

name = "name of the workers"
account_id = "fill in the Account ID you copied above"
main = "src/index.ts"
workers_dev = true
compatibility_date = "2024-06-08"

kv_namespaces = [
	 { binding = "HAMMAL_CACHE", id = "your kv id" }
]
  1. Get the kv ID by executing the command below, which will output the id. Modify the id in the configuration.
npx wrangler kv:namespace create hammal_cache

Output

  1. Then deploy by executing:
pnpm run deploy

Warning

You will be prompted that you are about to publish a Workers service, which was last published through the Cloudflare Dashboard. Edits made through the Cloudflare Dashboard will be overwritten by your local code and configuration.

image

Enter y, and it will normally open a browser for you to authorize. Just authorize; I didn't get a prompt here because I had already deployed it before.

image
  1. Add a domain to the newly deployed Workers. image

Wait for the domain to take effect, and you can use it normally. Generally, you just need to modify /etc/docker/daemon.json on the server to configure the source address you just set up.

"registry-mirrors": [
    "https://hammal.example.com"
  ]

I am using Orbstack on Mac, so I need to configure it directly in the software.

image

This article was synchronized and updated to xLog by Mix Space. The original link is https://remrin.dev/posts/dev/docker

Loading...
Ownership of this post data is guaranteed by blockchain and smart contracts to the creator alone.