Docker 内pip安装package报错: Failed to establish a new connection: [Errno -3] Temporary failure in name resolution'
说来奇幻(对本菜来说, 经常遇到堪称奇幻的问题)
之前在docker里面各种安装都没问题, 也不知道什么引起的, 昨天晚上调试的时候卸载了一个包的版本,然后就安不上了.
宿主机安装依然各种流畅,唯独docker容器不行.
网上找了许多方法, 最后在 /etc/resolv.conf 文件内添加如下的代码解决了:
nameserver 8.8.8.8
https://blog.csdn.net/qq_17351077/article/details/77498173
上面的博客提到了这个方法,但是不明白什么原因, 所以就没试, 然后在
上又找到了同样的方案,这次这哥们给了点说明: Docker没有使用正确的DNS服务器。将谷歌的DNS服务器地址 添加到那个配置文件
Your problem comes from the fact that Docker is not using the proper DNS server. You can fix it in three different ways :
1. Adding Google DNS to your local config
Modifying /etc/resolv.conf and adding the following lines at the end
# Google IPv4 nameservers nameserver 8.8.8.8 nameserver 8.8.4.4
If you want to add other DNS servers, have a look here.
However this change won't be permanent (see this thread). To make it permanent : $ sudo nano /etc/dhcp/dhclient.conf
Uncomment and edit the line with prepend domain-name-server : prepend domain-name-servers 8.8.8.8, 8.8.4.4;
Restart dhclient : $ sudo dhclient
.
2. Modifying Docker config
Systems that run Ubuntu or an Ubuntu derivative on the desktop typically use 127.0.0.1 as the default nameserver in /etc/resolv.conf file.
To specify a DNS server for use by Docker :
1. Log into Ubuntu as a user with sudo privileges. 2. Open the /etc/default/docker file for editing : $ sudo nano /etc/default/docker 3. Add the following setting for Docker. DOCKER_OPTS="--dns 8.8.8.8" 4. Save and close the file. 5. Restart the Docker daemon : $ sudo systemctl restart docker
3. Using a parameter when you run Docker
When you run docker, simply add the following parameter : --dns 8.8.8.8
我是用的第一个方法, 虽然解决了, 但是为什么之前都没出现这个问题呢?
我服务器默认的是阿里云的DNS服务器地址, 查看了下我的电脑虚拟机的,用的是虚拟的局域网IP地址,
docker会继承宿主机的DNS服务器地址,难不成是阿里云的DNS服务器的问题?但是我宿主机没事
【推荐】国内首个AI IDE,深度理解中文开发场景,立即下载体验Trae
【推荐】编程新体验,更懂你的AI,立即体验豆包MarsCode编程助手
【推荐】抖音旗下AI助手豆包,你的智能百科全书,全免费不限次数
【推荐】轻量又高性能的 SSH 工具 IShell:AI 加持,快人一步
· 10年+ .NET Coder 心语,封装的思维:从隐藏、稳定开始理解其本质意义
· .NET Core 中如何实现缓存的预热?
· 从 HTTP 原因短语缺失研究 HTTP/2 和 HTTP/3 的设计差异
· AI与.NET技术实操系列:向量存储与相似性搜索在 .NET 中的实现
· 基于Microsoft.Extensions.AI核心库实现RAG应用
· TypeScript + Deepseek 打造卜卦网站:技术与玄学的结合
· 阿里巴巴 QwQ-32B真的超越了 DeepSeek R-1吗?
· 【译】Visual Studio 中新的强大生产力特性
· 10年+ .NET Coder 心语 ── 封装的思维:从隐藏、稳定开始理解其本质意义
· 【设计模式】告别冗长if-else语句:使用策略模式优化代码结构