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

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

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

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

  1. 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. 1. Log into Ubuntu as a user with sudo privileges.
  2. 2. Open the /etc/default/docker file for editing :
  3. $ sudo nano /etc/default/docker
  4. 3. Add the following setting for Docker.
  5. DOCKER_OPTS="--dns 8.8.8.8"
  6. 4. Save and close the file.
  7. 5. Restart the Docker daemon :
  8. $ 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服务器的问题?但是我宿主机没事

Docker 内pip安装package报错: Failed to establish a new connection: [Errno -3] Temporary failure in name resolution'的更多相关文章

  1. 启动hadoop时候报错:localhost: ssh: Could not resolve hostname localhost: Temporary failure in name resolution”

    这个错误是由于配置文件没有配置好.解决方案如下: 1 打开profile文件 vim /etc/profile 2 在文件最后加入的内容应该如下(高亮的两句一般是大家缺少的): export JAVA ...

  2. pycharm安装 package报错:module 'pip' has no attribute 'main'

    转自: <pycharm安装 package报错:module 'pip' has no attribute 'main'> https://www.cnblogs.com/Fordest ...

  3. Pycharm安装package报错:AttributeError: module 'pip' has no attribute 'main'

    Pycharm安装package报错:AttributeError: module 'pip' has no attribute 'main' 确认pip已经升级到目前最新版本了. 在网上搜寻后,解决 ...

  4. pip安装pycrypto报错:Microsoft Visual C++ 14.0 is required. 和 SSLError: HTTPSConnectionPool的解决办法

    今天本打算把[Python3爬虫]网易云音乐爬虫 的代码敲一遍, 但是在安装pycrypto老是报错, 由于我计算是win10, 并且也有vs2017 python3环境下安装pycrypto的一些问 ...

  5. windows安装anaconda 报错failed to create anacoda menu ?

    windows安装anaconda 报错failed to create anacoda menu ? 装了无数次,每次都是 failed to create anacoda menu然后无选择忽略, ...

  6. pip安装软件报错 utf-8 code can't decode byte 0xcf in position7

    pip安装软件报错 utf-8 code can't decode byte 0xcf in position7 根据错误提示的路径找到__init__.py文件 根据错误提示的最后几句话找到对应的行 ...

  7. python pip安装模块报错 "Can't connect to HTTPS URL because the SSL module is not available."

    在升级python版本为3.6之后,pip安装模块报错. 报错信息如图: 原因是系统自带的openssl版本与python3的版本不匹配,所以这里只要升级openssl版本就可以解决问题. yum - ...

  8. pip安装setuptools_rust报错

    公司项目中有主备CDN存在,由于阿里云以及腾讯云的预热功能不支持自动(一般是云函数),所以就根据云厂商给的脚本稍作更改,手动传入数据来进行预热. 由于之前部署在centos7.7系统python2.7 ...

  9. 解决vue安装less报错Failed to compile with 1 errors的问题

    1.创建vue项目后安装less,执行 npm install less less-loader --save-dev 下载版本为:less-loader@6.1.0 , less@3.11.3,重启 ...

随机推荐

  1. 多层全连接神经网络实现minist手写数字分类

    import torch import numpy as np import torch.nn as nn from torch.autograd import Variable import tor ...

  2. jQuery easyui datagrid 的数据加载

        其实easyuidatagrid加载数据只有两种方式:一种是ajax加载目标url返回的json数据:另一种是加载js对象,也就是使用loadDate方法,这种方法用于加载本地js数据(非ur ...

  3. webpack 自动运行,及打包 img css json 的操作 npm插件的使用方法

    没有指令操作的属性生产环境,有指令操作的属于开发环境 webpack:输入指令后,便会自动开启一个浏览器 需要插件:open-browser-webpack-plugin 生产环境 想使用 node. ...

  4. Python 写 ACM 题目的一些技巧

    目录 输入输出 input() 输入 split() 用于输入 strip() 输入清理 print() 输入 sort 排序 输入输出 input() 输入 Python3 中 input() 函数 ...

  5. mysql查询时特殊字符转译

    commons.lang String value = StringEscapeUtils.escapeSql(searchRequest.getSearchValue());

  6. Delphi XE2 之 FireMonkey 入门(44) - 控件基础: TTreeView、TTreeViewItem

    Delphi XE2 之 FireMonkey 入门(44) - 控件基础: TTreeView.TTreeViewItem TScrollBox -> TCustomTreeView -> ...

  7. 阶段3 1.Mybatis_05.使用Mybatis完成CRUD_1 回顾Mybatis的环境搭建-实现查询所有功能

    先回顾Mybits的环境搭建,. 直接next 直接点击finish 创建好的项目. 所有东西都自己写不现实,约束文件的头部还是拷贝过来 导入依赖坐标,Mybits mysql的驱动 log4j 单元 ...

  8. tomcat 404 The origin server did not find a current representation for the target resource or is not willing to disclose that one exists.

    1.原因 tomcat没有找到项目,因为是用eclipse启动的,不是在tomcat的目录下启动,所以我们需要在eclipse下配置启动目录,好让tomcat找到项目. 2.解决 用本地安装的tomc ...

  9. & 和 && 区别和联系,| 和 || 区别和联系

    & 和 && 区别和联系,| 和 || 区别和联系,实际项目中,什么情况用哪种? 首先,& 和 && 的联系(共同点): & 和 &&a ...

  10. https=http+ssl

    TLS/SSL中使用了非对称加密,对称加密以及HASH算法.握手过程的具体描述如下: 浏览器将自己支持的一套加密规则发送给网站. 网站从中选出一组加密算法与HASH算法,并将自己的身份信息以证书的形式 ...