docker拉取镜像失败的解决方案大全

更换国内源

创建或修改 /etc/docker/daemon.json 文件,修改:

{
    "registry-mirrors" : [
    "https://registry.docker-cn.com",
    "http://hub-mirror.c.163.com",
    "https://docker.mirrors.ustc.edu.cn",
    "https://cr.console.aliyun.com",
    "https://mirror.ccs.tencentyun.com"
  ]
}

下面是一些国内镜像源:

Docker中国区官方镜像:
https://registry.docker-cn.com

网易:
http://hub-mirror.c.163.com

ustc:
https://docker.mirrors.ustc.edu.cn

中国科技大学:
https://docker.mirrors.ustc.edu.cn

阿里云:
https://cr.console.aliyun.com/

腾讯云:
https://mirror.ccs.tencentyun.com

重启docker服务使配置生效:

systemctl daemon-reload
systemctl restart docker.service

查看配置是否成功:

docker info

在这里插入图片描述

Registry Mirrors:有截图中框起来的就说明配置成功。
在这里插入图片描述

cl in docker

拉取cl镜像

 docker pull dreamacro/clash

打开容器

 docker ps -a

运行cl

config.yaml配置文件可以联系我获取,微信在文末:

 docker run -d --name clash --restart always -p 7890:7890 -p 7891:7891 -p 9090:9090 -v /home/user/Desktop/xxx/config.yaml:/root/.config/clash/config.yaml dreamacro/clash

检查cl配置

docker inspect cl

找到network 下的 IP addres

"Networks": {
                "bridge": {
                    "IPAMConfig": null,
                    "Links": null,
                    "Aliases": null,
                    "NetworkID": "fbe81fd305ccd324f831173adbb3ceaec3142835ef4763bb4fd01e5499cd4be4",
                    "EndpointID": "fcc3b650396b1caf173fe0308b2b22e068186b0cd87a05ee635679367b7f0284",
                    "Gateway": "172.17.0.1",
                    "IPAddress": "172.17.0.2",
                    "IPPrefixLen": 16, 
                    "IPv6Gateway": "",
                    "GlobalIPv6Address": "",
                    "GlobalIPv6PrefixLen": 0,
                    "MacAddress": "02:42:ac:11:00:02",
                    "DriverOpts": null 
                }
            }

将ip地址写入docker配置

sudo vim /usr/lib/systemd/system/docker.service
[Service]
Type=notify 
# the default is not to use systemd for cgroups because the delegate issues still
# exists and systemd currently does not support the cgroup feature set required
# for containers run by docker
ExecStart=/usr/bin/dockerd -H fd:// --containerd=/run/containerd/containerd.sock
ExecReload=/bin/kill -s HUP $MAINPID
TimeoutSec=0
RestartSec=2
Restart=always

重启docker

sudo systemctl daemon-reload
sudo systemctl restart docker
### 解决 Docker Pull 镜像失败的方法 当遇到 `docker pull` 操作失败的情况时,可能的原因包括网络连接不稳定、默认镜像源速度过慢或不可达等问题。针对这些问题有多种有效的解决方案。 #### 使用国内镜像加速器 为了提高下载效率并减少错误发生率,建议配置国内的Docker镜像加速服务。常见的可选地址如下: - 百度云提供的公共仓库:`https://mirror.baidubce.com`[^1] - 南京大学开源软件镜像站:`https://docker.nju.edu.cn`[^1] 这些站点能够显著改善中国地区的访问体验,加快镜像的速度。 #### 修改 Docker Daemon 设置 通过编辑 `/etc/docker/daemon.json` 文件来设置镜像加速链接是一个常用的做法。具体操作为使用文本编辑工具打开该文件,并加入以下内容之一作为配置项: ```json { "registry-mirrors": [ "https://daocloud.io", "https://9cpn8tt6.mirror.aliyuncs.com", "https://registry.docker-cn.com" ] } ``` 上述 JSON 片段中的 URL 列表提供了多个可靠的镜像源选项[^3]。完成修改之后保存更改并退出编辑模式。 #### 更新 DNS 配置 (可选) 对于某些特定环境下的问题,还可以尝试调整系统的DNS解析服务器至更稳定的服务提供商处,比如Google Public DNS: ```bash vi /etc/resolv.conf ``` 将其中的内容替换为: ``` nameserver 8.8.8.8 nameserver 8.8.4.4 ``` 这一步骤并非总是必要的,但在某些情况下可以帮助解决问题。 #### 应用变更 最后,在完成了以上任何一项改动后都需要重新加载守护进程配置以及重启 Docker 服务以使新设定生效: ```shell systemctl daemon-reload systemctl restart docker ``` 这样就能确保所有的更新都被正确应用到当前环境中去了。
评论 15
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值