docker换源


前言

在pull镜像时遇到如下报错:

┌──(root㉿kali)-[/home/longl]
└─# docker pull hello-world 
Using default tag: latest
latest: Pulling from library/hello-world
c1ec31eb5944: Retrying in 1 second 
error pulling image configuration: download failed after attempts=6: dial tcp 173.252.88.67:443: connect: connection refused

解决方法:换源!!!!!!!!!

1. 查找可用的镜像源

首先,你需要找到一个可用的镜像源。一些常见的国内镜像源包括:

  • 阿里云:https://registry.cn-hangzhou.aliyuncs.com
  • 腾讯云:https://mirrors.tencent.com/docker
  • 华为云:https://mirror.ccs.tencent.com/dockerhub
  • 中国科技大学:https://docker.mirrors.ustc.edu.cn/
  • 豆瓣(Douban):https://dockerhub.douban.com/

注意阿里云提供:
[系统分配前缀].mirror.aliyuncs.com
具体上阿里云容器HUB控制台查看(需要账号)
阿里云容器HUB控制台:
https://cr.console.aliyun.com/cn-hangzhou/instances/mirrors

在这里插入图片描述

2. 配置 Docker 镜像源

Docker 可以通过修改配置文件来更换镜像源。你可以使用 Docker 提供的 daemon.json 文件来配置镜像源。

  1. 打开或创建 daemon.json 文件。这个文件通常位于 /etc/docker/ 目录下:
    如果没有创建daemon.json文件就自己创建一下

    sudo touch /etc/docker/daemon.json
    

    编辑daemon.json

    sudo vim /etc/docker/daemon.json
    
  2. daemon.json 文件中添加以下内容,将 MIRRORS 替换为你选择的镜像源:

    {
      "registry-mirrors": ["https://MIRRORS.mirror.com"]
    }
    

    例如,如果你想使用中科大的镜像源,你应该这样写:

    {
      "registry-mirrors": ["https://docker.mirrors.ustc.edu.cn/"]
    }
    

    建议使用阿里的镜像加速器提供的源

  3. 保存并关闭文件。

3. 重启 Docker 服务

配置完成后,需要重启 Docker 服务以使配置生效:

sudo systemctl restart docker

4. 查看dock info是否修改成功

如果修改成功,可以在info中查看到修改后的源:

sudo docker info

5. 验证镜像源是否更换成功

为了验证是否成功更换了镜像源,你可以尝试拉取一个镜像,比如 hello-world

docker pull hello-world

如果镜像成功下载,并且过程中没有出现之前的错误,那么更换镜像源就成功了。

成功!!!!

┌──(root㉿kali)-[/etc/docker]
└─# docker pull hello-world
Using default tag: latest
latest: Pulling from library/hello-world
2db29710123e: Pull complete 
Digest: sha256:2498fce14358aa50ead0cc6c19990fc6ff866ce72aeb5546e1d59caac3d0d60f
Status: Downloaded newer image for hello-world:latest
docker.io/library/hello-world:latest

┌──(root㉿kali)-[/etc/docker]
└─# docker image ls        
REPOSITORY    TAG       IMAGE ID       CREATED       SIZE
hello-world   latest    feb5d9fea6a5   2 years ago   13.3kB

注意事项

  • 确保你使用的镜像源支持你想要拉取的镜像。
  • 有些镜像源可能需要认证,这种情况下你需要在 Docker 的配置中添加认证信息。
  • 如果你在使用 Docker Compose,你可能还需要配置 .env 文件或 Docker Compose 的配置文件来指定镜像源。

更换镜像源是一个常见的操作,特别是在网络条件不佳或者需要访问特定地区镜像源的情况下。通过上述步骤,你应该能够顺利地更换 Docker 的镜像源。

  • 19
    点赞
  • 20
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值