使用docker环境报错解决#ERROR: Error response from daemon: Get “https://registry-1.docker.io/v2/

文章讲述了在CentOS系统中遇到的Docker运行远程镜像失败的问题,原因在于DNS解析问题。通过编辑resolv.conf文件,将nameserver更改为8.8.8.8并确保DNS设置在重启后保持,解决了Docker无法拉取镜像的问题。

摘要生成于 C知道 ,由 DeepSeek-R1 满血版支持, 前往体验 >

问题:docker 无法run远程库

[root@localhost docker]# docker run hello-world
Unable to find image 'hello-world:latest' locally
docker: Error response from daemon: Get "https://registry-1.docker.io/v2/": net/http: request canceled while waiting for connection (Client.Timeout exceeded while awaiting headers).

解决方案:
用vi打开/etc/resolv.conf

vi resolv.conf

将 nameserver 改成 8.8.8.8

# Generated by NetworkManager
search localdomain
#nameserver 192.168.231.2
nameserver 8.8.8.8

然后重启docker

sudo systemctl restart docker

run 成功

[root@localhost etc]# docker run hello-world
Unable to find image 'hello-world:latest' locally
latest: Pulling from library/hello-world
719385e32844: Pull complete 

还需要注意的是机器重启之后,上面设置会失效,重启服务器DNS就会被强制还原
需要在网卡设置中修改NM_CONTROLLED的值
在/etc/sysconfig/network-scripts/ifcfg-eth33中修改内容:

NM_CONTROLLED="no" //是否允许Network Manager管理,设置为no

在同一文件中设置

PEERDNS="yes"
DNS1="xxx.xxx.xxx.xxx"
DNS2="xxx.xxx.xxx.xxx"

修改完毕之后重启网卡:

service network restart

参考链接:Error response from daemon: Get https://registry-1.docker.io/v2/: Docker报错解决方案
详解CentOS重启后resolv.conf被重置的解决方案

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值