解决contos8 docker pip3安装失败 Temporary failure in name resolution
背景
使用Dockerfile
部署一个爬虫项目出现emporary failure in name resolution
执行语句
RUN pip3 install -i http://mirrors.aliyun.com/pypi/simple/ --trusted-host mirrors.aliyun.com -r requirements.txt
出现上诉问题
起因
可能是 contos8 和 docker DNS 解析存在冲突,细心的你会发现 使用ip 进行外网ping 是可以ping 192.168.56.10
ping
得通的,但是使用域名就请求被拒绝访问
,这其实和dns解析有关。
使用 某云 centos7 未出现此类问题。
使用 某云 centos8 却出现。
解决方案
配置docker DNS 解析
将/etc/resolv.conf
本机解析ip
复制到/etc/docker/daemon.json
配置,进行如下配置
# cat /etc/resolv.conf
# cat /etc/docker/daemon.json
vi /etc/docker/daemon.json
[root@VM-8-9-centos ~]# cat /etc/resolv.conf
# Generated by NetworkManager
nameserver 183.60.83.54
nameserver 183.60.82.43
[root@VM-8-9-centos ~]# cat /etc/docker/daemon.json
{
"registry-mirrors": ["https://l90lo6hm.mirror.aliyuncs.com"],
"dns":["183.60.83.54","183.60.82.43"]
}
配置dns即可
记得重启docker
sudo systemctl daemon-reload
sudo systemctl restart docker
说明
本次修改针对的是云主机环境配置,如果你使用的使用本地contos8
可参考此作者的郑赫博客
https://blog.csdn.net/weixin_45230118/article/details/102639115