我正在遵循无花果指南,使用具有python应用程序的docker,但是当docker达到命令时
运行点安装-r requirements.txt我收到以下错误消息:
步骤3:运行pip install -r requirements.txt --->运行在fe0b84217ad1 收集闪烁== 1.3(从-r requirements.txt(行1))重试(重试(总= 4,连接=无,读=无,重定向=无))连接断开'ProtocolError('Connection aborted。',gaierror(-2,'Name or service not known'))':/ simple / blinker /重复几次,然后我收到另一个消息:
找不到满足要求的任何下载的命令===================================================================================================================================================================================== $ b所以由于某种原因,pip无法访问docker容器内的任何包。有没有什么我需要做的,以允许它的互联网访问?
但是pip可以很好地安装在docker容器之外的东西,甚至可以使用精确的包( blinker == 1.3 )所以这不是问题。另外这个问题不是特定于该包。任何软件包中的任何 pip install 命令都会遇到相同的问题。
有没有人知道发生了什么这里?
解决方案您的问题来自于Docker不使用正确的DNS服务器。 您可以通过三种不同的方式进行修复:
1。将Google DNS添加到本地配置中修改/etc/resolv.conf并在末尾添加以下行$ /
#Google IPv4名称服务器名称服务器8.8.8.8 名称服务器8.8.4.4
如果要添加其他DNS服务器,请查看这里。
但是,此更改不会是永久性的(请参阅这个线程)。要使其永久性: $ sudo nano /etc/dhcp/dhclient.conf 取消注释并使用前缀domain-名称服务器: 前缀域名服务器8.8.8.8,8.8.4.4;
重新启动dhclient: $ sudo dhclient 。
2。修改Docker配置As 在文档中解释:
运行Ubuntu或Ubuntu的系统派生在桌面上通常使用127.0.0.1作为/etc/resolv.conf文件中的默认名称服务器。
指定一个DNS服务器供Docker使用:
1。以具有sudo权限的用户身份登录Ubuntu。 2.打开/ etc / default / docker文件进行编辑: $ sudo nano / etc / default / docker 3.添加Docker的后续设置。 DOCKER_OPTS = - dns 8.8.8.8 4.保存并关闭文件。 5.重新启动Docker守护程序: $ sudo restart docker
3。运行Docker时使用参数
运行docker时,只需添加以下参数: - dns 8.8.8.8
I'm following the fig guide to using docker with a python application, but when docker gets up to the command
RUN pip install -r requirements.txtI get the following error message:
Step 3 : RUN pip install -r requirements.txt ---> Running in fe0b84217ad1 Collecting blinker==1.3 (from -r requirements.txt (line 1)) Retrying (Retry(total=4, connect=None, read=None, redirect=None)) after connection broken by 'ProtocolError('Connection aborted.', gaierror(-2, 'Name or service not known'))': /simple/blinker/This repeats several times and then I get another message:
Could not find any downloads that satisfy the requirement blinker==1.3 (from -r requirements.txt (line 1)) No distributions at all found for blinker==1.3 (from -r requirements.txt (line 1))So for some reason pip can't access any packages from inside a docker container. Is there anything I need to do to allow it internet access?
However pip works fine to install things outside of the docker container, and worked fine even with that exact package (blinker==1.3) so that's not the problem. Also this problem isn't specific to that package. I get the same issue with any pip install command for any package.
Does anyone have any idea what's going on here?
解决方案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 configModifying /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 configAs 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 followin setting for Docker. DOCKER_OPTS="--dns 8.8.8.8" 4. Save and close the file. 5. Restart the Docker daemon : $ sudo restart docker
3. Using a parameter when you run Docker
When you run docker, simply add the following parameter : --dns 8.8.8.8
更多推荐
不能在Ubuntu的Docker容器内安装pip软件包
发布评论