--------------------------------------------(建议直接看解决方案部分) --------------------------------------------
问题描述
按照官网安装完Docker,在最后一步检验docker是否安装成功,即运行sudo docker run hello-world这条命令时一直一直一直出现以下问题:
Unable to find image 'hello-world:latest' locally
latest: Pulling from library/hello-world
c1ec31eb5944: Retrying in 1 second
docker: error pulling image configuration: download failed after attempts=6: dial tcp 162.125.82.7:443: connect: connection refused.
See 'docker run --help'.
如下图:
然后尝试了很多种方法,例如:
方法二: 使用docker拉取镜像一直网路拒绝连接 - 守漠待花开 - 博客园 (cnblogs.com)
其中对于方法一中添加的镜像加速地址,网上有很多版本,比如只配置了阿里加速、只配置了中科大加速、只配置了网易加速.......
【看了很多对于这个问题的解决方案,都跟方案一很相似,觉得这个并不是问题的解(因为先入为主,先看了方案一,再看的其它版本的)就没有再去试其它同类型的答案的方法!】
并且!因为我看方法一中包含的比较多源,认为这都不行,就觉得这个不是产生问题的原因,如图:
然后,我开始找其它的方法,例如,方法三,此时就是方法一 + 方法三都不行!
又经过了2天的折腾以后,重新回到方法一类似的解法上来,再很认真看了其它的方法(http://t.csdnimg.cn/T5gt0)后,发现自己所用的方法一中并没有阿里镜像加速器!
于是想着试试,把阿里镜像加速器加入到配置文件中,没想到加入阿里镜像服务器后就运行成功了!!!
最终配置文件如下:
{"registry-mirrors": [
"https://s*****fq.mirror.aliyuncs.com",
"https://registry.docker-cn.com",
"https://docker.mirrors.ustc.edu.cn",
"https://hub-mirror.c.163.com",
"https://mirror.baidubce.com"
]
}
解决方案
1、首先检查是否存在daemon.json文件,如果没有,就需要创建:
sudo vim /etc/docker/daemon.json
//下面为创建方法,如果直接已经有了daemon.json文件,请忽略!
sudo mkdir -p /etc/docker //创建目录
2、然后在文件中插入如下内容:
{"registry-mirrors": [
"https://s*****fq.mirror.aliyuncs.com",
"https://registry.docker-cn.com",
"https://docker.mirrors.ustc.edu.cn",
"https://hub-mirror.c.163.com",
"https://mirror.baidubce.com"
]
}
【注意】阿里镜像加速器必须加上!!!
阿里镜像加速器的地址为:容器镜像服务 (aliyun.com)
其它镜像加速器可照抄
3、重启Docker服务
sudo systemctl daemon-reload
sudo systemctl restart docker
4、重新运行hello-world