Docker 内pip安装package报错: Failed to establish a new connection: [Errno -3] Temporary failure in name r...

说来奇幻(对本菜来说, 经常遇到堪称奇幻的问题)

之前在docker里面各种安装都没问题, 也不知道什么引起的, 昨天晚上调试的时候卸载了一个包的版本,然后就安不上了.

宿主机安装依然各种流畅,唯独docker容器不行.

网上找了许多方法, 最后在 /etc/resolv.conf 文件内添加如下的代码解决了:

nameserver 8.8.8.8

https://blog.csdn.net/qq_17351077/article/details/77498173

上面的博客提到了这个方法,但是不明白什么原因, 所以就没试, 然后在

https://stackoverflow.com/questions/28668180/cant-install-pip-packages-inside-a-docker-container-with-ubuntu/41989423

上又找到了同样的方案,这次这哥们给了点说明:  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

As explained in the docs :

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服务器的问题?但是我宿主机没事

 

转载于:https://www.cnblogs.com/haiton/p/11314102.html

  • 2
    点赞
  • 3
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值