奋斗
努力

京东云服务器怎么配置docker镜像源?

云计算

在京东云服务器(如京东云的云主机)上配置 Docker 镜像源,主要是为了提速 Docker 镜像的拉取,避免因默认使用 Docker Hub 国际源导致速度慢或拉取失败的问题。以下是配置 Docker 镜像源(镜像提速器)的详细步骤:


✅ 步骤一:安装 Docker(如未安装)

  1. 更新系统包:

    sudo yum update -y   # CentOS/RedHat
    # 或
    sudo apt update      # Ubuntu/Debian
  2. 安装 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
  3. 启动并设置开机自启:

    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 配置文件

  1. 编辑配置文件:

    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"
     ]
    }
  2. 重启 Docker 服务:

    sudo systemctl daemon-reload
    sudo systemctl restart docker
  3. 验证配置是否生效:

    docker info

    查看输出中是否有:

    Registry Mirrors:
    https://xxxxx.mirror.aliyuncs.com/
    https://docker.mirrors.ustc.edu.cn/

✅ 可选:京东云容器镜像服务(私有镜像仓库)

如果你希望使用京东云提供的私有镜像仓库(类似阿里云ACR),可以:

  1. 登录 京东云容器镜像服务控制台
  2. 创建私有仓库
  3. 配置 Docker 登录认证:
    docker login -u <your-username> -p <your-password> cr.cn-north-1.jcloudcs.com
  4. 推送/拉取镜像:
    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、私有仓库等),可继续提问。

未经允许不得转载:云服务器 » 京东云服务器怎么配置docker镜像源?