控制台面板 -> 左侧 Workers 和 Pages -> 创建应用程序 -> 创建 Worker -> 点击保存 -> 点击完成 -> 编辑代码
worker.js:
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37
| import HTML from './docker.html'; export default { async fetch(request) { const url = new URL(request.url); const path = url.pathname; const originalHost = request.headers.get("host"); const registryHost = "registry-1.docker.io"; if (path.startsWith("/v2/")) { const headers = new Headers(request.headers); headers.set("host", registryHost); const registryUrl = `https://${registryHost}${path}`; const registryRequest = new Request(registryUrl, { method: request.method, headers: headers, body: request.body, redirect: "follow", }); const registryResponse = await fetch(registryRequest); console.log(registryResponse.status); const responseHeaders = new Headers(registryResponse.headers); responseHeaders.set("access-control-allow-origin", originalHost); responseHeaders.set("access-control-allow-headers", "Authorization"); return new Response(registryResponse.body, { status: registryResponse.status, statusText: registryResponse.statusText, headers: responseHeaders, }); } else { return new Response(HTML.replace(/{{host}}/g, originalHost), { status: 200, headers: { "content-type": "text/html" } }); } } }
|
新建文件 docker.html 内容:
1 2 3 4 5 6 7 8 9 10
| <!DOCTYPE html> <html lang="zh-CN"> <head> <meta charset="utf-8"> <meta name="viewport" content="width=device-width, initial-scale=1"> <title></title> </head> <body> </body> </html>
|
点击部署
然后绑定自定义域名
设置 -> 触发器 -> 自定义域 -> 点击【添加自定义域】
注意:域名DNS服务器要设置到Cloudflare,由Cloudflare管理DNS解析记录。因为worker page自定义域名只支持他自己管理DNS记录的域名。
服务器:
vim /etc/docker/deamon.json
{
“registry-mirrors”: [“https://你的自定义域.com/“]
}
sudo systemctl daemon-reload
sudo systemctl restart docker
拉取镜像
docker pull 你的自定义域.com/koishijs/koishi:latest
删除镜像
docker rmi 你的自定义域.com/koishijs/koishi:latest