运维

运维相关知识和内容

Docker Hub国内加速方案:2026年最新配置指南

一、问题背景

2026年Docker Hub在国内访问持续不稳定,官方镜像站点时常超时。

1.1 问题表现

docker pull nginx
# Error response from daemon: Get https://registry-1.docker.io/v2/:
# net/http: request canceled while waiting for connection

二、配置镜像加速器

2.1 阿里云镜像加速器

获取加速地址:访问 https://cr.console.aliyun.com/cn-hangzhou/instances/mirrors

Linux配置

sudo mkdir -p /etc/docker
sudo tee /etc/docker/daemon.json <<EOF
{
  "registry-mirrors": ["https://xxxx.mirror.aliyuncs.com"]
}
EOF

sudo systemctl daemon-reload
sudo systemctl restart docker

2.2 多镜像源配置

{
  "registry-mirrors": [
    "https://docker.1ms.run",
    "https://docker.xuanyuan.me",
    "https://huecker.io",
    "http://f1361db2.m.daocloud.io"
  ]
}

三、配置Docker代理

3.1 系统代理

sudo mkdir -p /etc/systemd/system/docker.service.d
sudo tee /etc/systemd/system/docker.service.d/http-proxy.conf <<EOF
[Service]
Environment="HTTP_PROXY=http://proxy.example.com:8080"
Environment="HTTPS_PROXY=http://proxy.example.com:8080"
EOF

sudo systemctl daemon-reload
sudo systemctl restart docker

四、离线镜像方案

4.1 导出导入镜像

# 服务器A:导出镜像
docker save -o nginx.tar nginx:latest

# 传输到服务器B
scp nginx.tar user@serverB:/tmp/

# 服务器B:导入镜像
docker load -i /tmp/nginx.tar

五、验证配置

docker info | grep "Registry Mirrors"
time docker pull nginx:latest

六、总结

方案稳定性速度适用场景
阿里云镜像通用
多源配置稳定生产环境
科学上网依赖代理最快开发测试