解决方法
先上解决方法,具体问题见下方
# systemctl disable firewalld
# reboot
可能原因是centos8与docker的兼容问题,所以需要关闭防火墙。
具体问题
Step 8/9 : RUN pip install -r requirements.txt -i https://pypi.tuna.tsinghua.edu.cn/simple
---> Running in 950f24a15725
Looking in indexes: https://pypi.tuna.tsinghua.edu.cn/simple
WARNING: Retrying (Retry(total=4, connect=None, read=None, redirect=None, status=None)) after connection broken by 'NewConnectionError('<pip._vendor.urllib3.connection.VerifiedHTTPSConnection object at 0x7fb7626cd610>: Failed to establish a new connection: [Errno -3] Temporary failure in name resolution')': /simple/django/
WARNING: Retrying (Retry(total=3, connect=None, read=None, redirect=None, status=None)) after connection broken by 'NewConnectionError('<pip._vendor.urllib3.connection.VerifiedHTTPSConnection object at 0x7fb7626c8ed0>: Failed to establish a new connection: [Errno -3] Temporary failure in name resolution')': /simple/django/
WARNING: Retrying (Retry(total=2, connect=None, read=None, redirect=None, status=None)) after connection broken by 'NewConnectionError('<pip._vendor.urllib3.connection.VerifiedHTTPSConnection object at 0x7fb7626c8d90>: Failed to establish a new connection: [Errno -3] Temporary failure in name resolution')': /simple/django/
WARNING: Retrying (Retry(total=1, connect=None, read=None, redirect=None, status=None)) after connection broken by 'NewConnectionError('<pip._vendor.urllib3.connection.VerifiedHTTPSConnection object at 0x7fb7626c8d10>: Failed to establish a new connection: [Errno -3] Temporary failure in name resolution')': /simple/django/
WARNING: Retrying (Retry(total=0, connect=None, read=None, redirect=None, status=None)) after connection broken by 'NewConnectionError('<pip._vendor.urllib3.connection.VerifiedHTTPSConnection object at 0x7fb7626c8990>: Failed to establish a new connection: [Errno -3] Temporary failure in name resolution')': /simple/django/
ERROR: Could not find a version that satisfies the requirement Django==2.2 (from -r requirements.txt (line 1)) (from versions: none)
ERROR: No matching distribution found for Django==2.2 (from -r requirements.txt (line 1))
ERROR: Service 'app' failed to build: The command '/bin/sh -c pip install -r requirements.txt -i https://pypi.tuna.tsinghua.edu.cn/simple' returned a non-zero code: 1
出现这个情况,第一时间尝试在非容器环境执行相同命令,命令正常执行,说明网络正常。搜索报错信息,给出的一般是DNS相关情况,也有一篇文章指出是内存的原因。
进一步确认,尝试在docker环境中ping网络,情况如下。
Step 3/11 : RUN ping -w 4 163.177.151.110 #百度ip
---> Running in fca30cd8d31e
PING 163.177.151.110 (163.177.151.110) 56(84) bytes of data.
64 bytes from 163.177.151.110: icmp_seq=1 ttl=54 time=39.8 ms
64 bytes from 163.177.151.110: icmp_seq=2 ttl=54 time=26.1 ms
64 bytes from 163.177.151.110: icmp_seq=3 ttl=54 time=24.10 ms
64 bytes from 163.177.151.110: icmp_seq=4 ttl=54 time=23.8 ms
--- 163.177.151.110 ping statistics ---
4 packets transmitted, 4 received, 0% packet loss, time 8ms
rtt min/avg/max/mdev = 23.782/28.668/39.784/6.473 ms
Removing intermediate container fca30cd8d31e
---> 5febbab41d2d
Step 4/11 : RUN ping -w 4 www.baidu.com #百度域名
---> Running in 66dc4902963d
ping: www.baidu.com: Temporary failure in name resolution
ERROR: Service 'app' failed to build: The command '/bin/sh -c ping -w 4 www.baidu.com #百度域名' returned a non-zero code: 2
可见应该是DNS问题。
解决过程
查资料
查CSDN,百度,google,得到的解决方式大多是DNS问题。解决DNS的方法主要有以下几种:
1、修改/etc/resolv.conf
$ vim /etc/resolv.conf
#增加如下内容
nameserver 8.8.8.8
nameserver 8.8.8.4
$systemctl restart NetworkManager
如果再次
$cat /etc/resolv.conf
输出内容有变的话(文件包含#Generated from NetworkManager),可以
$ chattr +i /etc/resolv.conf
或者手动配置/etc/sysconfig/network-scripts/ifcfg-ens22
文件,具体请搜索linux配置网络。
2、创建或增加r内容至文件/etc/docker/daemon.json
$vim /etc/docker/daemon.json
{
"dns":["8.8.8.8",
"8.8.4.4"
]
}
最后,https://www.dedoimedo.com/computers/docker-container-no-network.html,该链接内容提供了一个非常完整的思路。
但是,执行了以上所有内容,都无法解决问题,即除了开始提供的关闭防火墙方法,一切都没用,真的坑啊。
解决后
Step 8/9 : RUN pip install -r requirements.txt -i https://pypi.tuna.tsinghua.edu.cn/simple
---> Running in 8504c8002a9e
Looking in indexes: https://pypi.tuna.tsinghua.edu.cn/simple
Collecting Django==2.2
Downloading https://pypi.tuna.tsinghua.edu.cn/packages/54/85/0bef63668fb170888c1a2970ec897d4528d6072f32dee27653381a332642/Django-2.2-py3-none-any.whl (7.4MB)
Collecting django-allauth==0.39.1
Downloading https://pypi.tuna.tsinghua.edu.cn/packages/9c/dc/b7821e2b62311e402c24749f32dcbc337501f1d87e4eb2d4ef19e1e95f31/django-allauth-0.39.1.tar.gz (534kB)
Collecting django-ckeditor==5.6.1
Downloading https://pypi.tuna.tsinghua.edu.cn/packages/a5/a7/9a6f039f950cb148bb60d9223bcafe31329b3c85dc9a3d9b74182649c343/django-ckeditor-5.6.1.tar.gz (1.6MB)
Collecting django-js-asset==1.2.2
Downloading https://pypi.tuna.tsinghua.edu.cn/packages/aa/2d/98089cf51c8e83bc70723021390b94a3638a4a0ce30a47e2e70476b2095d/django_js_asset-1.2.2-py2.py3-none-any.whl
Collecting django-model-utils==3.1.2
Downloading https://pypi.tuna.tsinghua.edu.cn/packages/d1/92/8a6b15368bb407f0a2e716bf603e73c843af782b98e68f23c19697742f8a/django_model_utils-3.1.2-py2.py3-none-any.whl
Collecting django-mptt==0.10.0
......