docker-国内使用
2025-2026 年在中国大陆不使用任何 VPN 的情况下,安装和正常使用 Docker 是完全可行的,但需要做两件事:
- 使用国内可访问的软件源安装 Docker 本身(清华源、阿里源、中科大源等)
- 配置国内镜像加速器(registry mirror),否则 pull 官方镜像会非常慢或直接失败
目前(2026年3月)主流还能稳定用的加速源主要集中在几家第三方和部分云厂商提供的公共源,高校源基本都关了。
推荐安装方式(最稳的几种)
方法1:使用 Docker 官方一键安装脚本(最推荐,2026年仍可用)
# 1. 清理旧版本(可选但推荐)
sudo apt-get remove docker docker-engine docker.io containerd runc # Debian/Ubuntu
# 或
sudo yum remove docker docker-client docker-client-latest docker-common docker-latest docker-latest-logrotate docker-logrotate docker-engine # CentOS/RHEL
# 2. 运行官方安装脚本(会自动选国内可访问的源)
curl -fsSL https://get.docker.com | sudo bash -s docker --mirror Aliyun
# 或者用清华源(有时候更快)
curl -fsSL https://get.docker.com | sudo bash -s docker --mirror Tsinghua
# 3. 启动并设置开机自启
sudo systemctl start docker
sudo systemctl enable docker
# 4. 验证
docker version
docker run hello-world
方法2:Ubuntu/Debian 手动安装(更可控)
sudo apt update
sudo apt install -y ca-certificates curl gnupg lsb-release
# 添加 Docker 官方 GPG 密钥(清华源方式)
sudo mkdir -p /etc/apt/keyrings
curl -fsSL https://mirrors.tuna.tsinghua.edu.cn/docker-ce/linux/ubuntu/gpg | sudo gpg --dearmor -o /etc/apt/keyrings/docker.gpg
# 添加源(选一个就行,按你系统版本改 codename)
echo \
"deb [arch=$(dpkg --print-architecture) signed-by=/etc/apt/keyrings/docker.gpg] https://mirrors.tuna.tsinghua.edu.cn/docker-ce/linux/ubuntu \
$(lsb_release -cs) stable" | sudo tee /etc/apt/sources.list.d/docker.list > /dev/null
# 阿里云源(备用)
# echo "deb [arch=$(dpkg --print-architecture) signed-by=/etc/apt/keyrings/docker.gpg] https://mirrors.aliyun.com/docker-ce/linux/ubuntu $(lsb_release -cs) stable" | sudo tee /etc/apt/sources.list.d/docker.list > /dev/null
sudo apt update
sudo apt install -y docker-ce docker-ce-cli containerd.io docker-compose-plugin
CentOS / Rocky / AlmaLinux 基本流程类似,只是用 yum 或 dnf。
最关键:配置镜像加速(不配置基本用不了)
2026 年还能用的公共镜像源(实测可用,按速度排序,建议多加几个):
{
"registry-mirrors": [
"https://docker.1panel.live",
"https://docker.1ms.run",
"https://docker.m.daocloud.io",
"https://docker.hpcloud.cloud",
"https://docker.xuanyuan.me",
"https://registry.cyou",
"https://hub.rat.dev"
]
}
配置步骤(Linux 通用):
sudo mkdir -p /etc/docker
sudo tee /etc/docker/daemon.json <<-'EOF'
{
"registry-mirrors": [
"https://docker.1panel.live",
"https://docker.1ms.run",
"https://docker.m.daocloud.io",
"https://docker.hpcloud.cloud",
"https://docker.xuanyuan.me"
]
}
EOF
sudo systemctl daemon-reload
sudo systemctl restart docker
配置完后建议测试:
docker pull alpine # 应该秒下
docker pull python:3.11-slim
快速总结表(2026年3月主流可用源)
| 优先级 | 镜像地址 | 备注 |
|---|---|---|
| ★★★★★ | https://docker.1panel.live | 目前最稳最快之一 |
| ★★★★☆ | https://docker.1ms.run | 支持HTTP/3,延迟很低 |
| ★★★★ | https://docker.m.daocloud.io | DaoCloud 维护,较稳定 |
| ★★★ | https://docker.xuanyuan.me | 免费版够用,专业版更强 |
| ★★★ | https://docker.hpcloud.cloud | 比较新,速度不错 |
| 备用 | https://registry.cyou | 容器镜像管理中心 |
最后几点建议
- 至少配置 3 个源,防止某一个突然不行
- 如果你用的是阿里云/腾讯云/华为云服务器,优先用它们内网专属加速地址(更快)
- Docker Desktop(Windows/Mac)在国内也建议同样配置 registry-mirrors(设置 → Docker Engine)
- 如果你主要跑 open source 镜像,基本够用了;如果需要大量 ghcr.io、quay.io、gcr.io 的镜像,还是得想办法(自建 proxy 或用付费机场中转)
照上面步骤做,2026 年大陆环境下 95% 的 Docker 使用场景都可以不翻墙完成。祝你 docker run 愉快~