在京东云服务器(如京东云的云主机)上配置 Docker 镜像源,主要是为了提速 Docker 镜像的拉取,避免因默认使用 Docker Hub 国际源导致速度慢或拉取失败的问题。以下是配置 Docker 镜像源(镜像提速器)的详细步骤:
✅ 步骤一:安装 Docker(如未安装)
-
更新系统包:
sudo yum update -y # CentOS/RedHat # 或 sudo apt update # Ubuntu/Debian -
安装 Docker:
sudo yum install -y docker # CentOS # 或 sudo apt install -y docker.io # Ubuntu或者使用官方脚本安装最新版:
curl -fsSL https://get.docker.com | bash -s docker --mirror Aliyun -
启动并设置开机自启:
sudo systemctl start docker sudo systemctl enable docker
✅ 步骤二:配置 Docker 镜像提速器
推荐使用国内镜像源,例如:
- 阿里云镜像提速器(推荐,需注册)
- 网易云:
http://hub-mirror.c.163.com - 中科大:
https://docker.mirrors.ustc.edu.cn - 腾讯云:
https://mirror.ccs.tencentyun.com
⚠️ 京东云本身不提供官方 Docker 镜像提速服务,但可以使用阿里云等第三方提速器。
方法:修改 Docker 的 daemon.json 配置文件
-
编辑配置文件:
sudo mkdir -p /etc/docker sudo tee /etc/docker/daemon.json <<-'EOF' { "registry-mirrors": [ "https://<your-aliyun-mirror>.mirror.aliyuncs.com", "https://docker.mirrors.ustc.edu.cn", "http://hub-mirror.c.163.com" ] } EOF🔁 替换
<your-aliyun-mirror>为你的阿里云账号专属提速地址(登录 阿里云容器镜像服务 获取)。示例(使用阿里云提速器):
{ "registry-mirrors": [ "https://xxxxx.mirror.aliyuncs.com", "https://docker.mirrors.ustc.edu.cn" ] } -
重启 Docker 服务:
sudo systemctl daemon-reload sudo systemctl restart docker -
验证配置是否生效:
docker info查看输出中是否有:
Registry Mirrors: https://xxxxx.mirror.aliyuncs.com/ https://docker.mirrors.ustc.edu.cn/
✅ 可选:京东云容器镜像服务(私有镜像仓库)
如果你希望使用京东云提供的私有镜像仓库(类似阿里云ACR),可以:
- 登录 京东云容器镜像服务控制台
- 创建私有仓库
- 配置 Docker 登录认证:
docker login -u <your-username> -p <your-password> cr.cn-north-1.jcloudcs.com - 推送/拉取镜像:
docker tag myimage cr.cn-north-1.jcloudcs.com/namespace/myimage:tag docker push cr.cn-north-1.jcloudcs.com/namespace/myimage:tag
✅ 总结
| 项目 | 推荐配置 |
|---|---|
| 镜像提速器 | 阿里云(需注册获取专属地址) |
| 备用源 | 中科大、网易云 |
| 配置文件 | /etc/docker/daemon.json |
| 重启命令 | systemctl restart docker |
如需进一步优化,可结合京东云内网拉取镜像(若使用京东云镜像仓库),减少公网流量和延迟。
如有具体操作系统或需求(如 Kubernetes、私有仓库等),可继续提问。
云服务器