0%

Cloudflare反代docker hub

控制台面板 -> 左侧 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

打包镜像为zip

若镜像不能用,可以在海外机器pull镜像后,打包镜像为压缩包,上传到国内机器,再加载镜像。

docker pull 自定义域.com/mlikiowa/napcat-docker:latest

docker save -o napcat.tar 自定义域.com/mlikiowa/napcat-docker:latest

将打包后的zip放到国内机器

加载镜像:
docker load -i napcat.tar

docker save -o napcat.tar hub.marchccc.top/mlikiowa/napcat-docker:latest

打包镜像为zip:
https://wutunan.top/%E8%BF%90%E7%BB%B4/windows/docker/%E6%80%8E%E4%B9%88%E5%B0%86%E9%95%9C%E5%83%8F%E6%89%93%E5%8C%85%E4%B8%BAzip.html#docker%E8%BF%99%E4%B9%88%E5%B0%86%E9%95%9C%E5%83%8F%E6%89%93%E5%8C%85%E5%88%B0%E6%9C%AC%E5%9C%B0

欢迎关注我的其它发布渠道