本帖最后由 atusu 于 2024-6-23 00:26 编辑
直接使用Nginx代理docker-hub镜像加速,简单粗暴
必须开启SSL
- # 用于 Docker 代理服务
- location /v2/ {
- proxy_pass https://registry-1.docker.io;
- proxy_set_header Host registry-1.docker.io;
- proxy_set_header X-Real-IP $remote_addr;
- proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;
- proxy_set_header X-Forwarded-Proto $scheme;
- proxy_buffering off;
- proxy_request_buffering off;
- proxy_http_version 1.1;
- proxy_read_timeout 7200s;
- proxy_send_timeout 7200s;
- send_timeout 7200s;
- proxy_connect_timeout 7200s;
- proxy_set_header Authorization $http_authorization;
- proxy_pass_header Authorization;
- proxy_intercept_errors on;
- recursive_error_pages on;
- error_page 301 302 307 = @handle_redirect;
- }
- location @handle_redirect {
- resolver 1.1.1.1;
- set $saved_redirect_location ‘$upstream_http_location’;
- proxy_pass $saved_redirect_location;
- }
- # 用于 Docker 代理服务
复制代码
记得去掉上图部分,不去掉拉取报错
配置镜像加速
- sudo tee /etc/docker/daemon.json <<EOF
- {
- "registry-mirrors": ["改成你的域名"]
- }
- EOF
复制代码
重启Docker服务
- sudo systemctl daemon-reload
- sudo systemctl restart docker
复制代码
拉取一个Docker镜像以测试配置是否生效
出现如下就是成功了
下面是测试拉取的几个较大的镜像都是成功没问题的
|