remrin

remrin

github
email

Build Docker Image Source Using Cloudflare Workers

A few days ago, all major mirror sites went down, and pulling Docker images became a problem.

At first, I didn't care much and just used a proxy to pull the images. But even with the proxy, I couldn't pull them properly when using Docker locally.

So I started looking for solutions and found the following options:

  • Build using Cloudflare Workers, which requires a domain -> Original Post
  • Self-build Nexus 3, which requires a foreign VPS with at least 4GB of memory and a domain -> Original Post
  • Use Github Action to transfer DockerHub images to Alibaba Cloud 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
  • As for other options, there are ready-made image sources, but they are generally not very stable, so I didn't consider them.

I used the first option, which is relatively simple. The tutorial in the original post is not very detailed, so I will provide more information here.

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

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

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

    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 and modify the name and account_id:

    name = "Name of the workers"
    account_id = "Paste the Account ID you copied earlier"
    main = "src/index.ts"
    workers_dev = true
    compatibility_date = "2024-06-08"
    
    kv_namespaces = [
        { binding = "HAMMAL_CACHE", id = "your kv id" }
    ]
    
  2. Get the kv ID by running the following command. It will output the ID, which you need to update in the configuration:

    npx wrangler kv:namespace create hammal_cache
    

    Output

  3. Deploy by running:

    pnpm run deploy
    

    Warning

    Here, you will be prompted that you are about to publish a Workers service. The last time this service was published was through the Cloudflare Dashboard. Any edits made through the Cloudflare Dashboard will be overwritten by your local code and configuration.

    image

    Enter y. Normally, a browser will open and ask for authorization. Grant the authorization. In my case, I have already deployed it, so it didn't pop up.

    image
  4. Add a domain to the newly deployed Workers.
    image
    Wait for the domain to take effect, and then you can use it normally. Usually, on the server, you just need to modify /etc/docker/daemon.json and configure the source address of your newly built mirror.

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

    On my Mac, I use Orbstack, so I need to configure it directly in the software.

    image

This article is 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.