解决dockerfile创建镜像时pip install报错的bug

dockerfile:

FROM python:3.7

RUN ln -sf /usr/share/zoneinfo/Asia/Shanghai /etc/localtime && echo "Asia/Shanghai" > /etc/timezone && \
  pip install -i https://pypi.tuna.tsinghua.edu.cn/simple/ \
  sanic==18.12.0 requests==2.20.0

ADD *.py /root/

CMD sh -c "python -u /root/test.py 1>>/root/nfs_root/test.log 2>>/root/nfs_root/test.err"

 

报错信息:

Sending build context to Docker daemon 3.584kB
Step 1/4 : FROM python:3.7
---> 9337bc3e7477
Step 2/4 : RUN ln -sf /usr/share/zoneinfo/Asia/Shanghai /etc/localtime && echo "Asia/Shanghai" > /etc/timezone && pip install -i https://pypi.tuna.tsinghua.edu.cn/simple/ sanic==18.12.0 requests==2.25.0
---> Running in 93c7852d9b62
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.HTTPSConnection object at 0x7fbe9f986c90>: Failed to establish a new connection: [Errno -3] Temporary failure in name resolution')': /simple/sanic/
WARNING: Retrying (Retry(total=3, connect=None, read=None, redirect=None, status=None)) after connection broken by 'NewConnectionError('<pip._vendor.urllib3.connection.HTTPSConnection object at 0x7fbe9ee1d390>: Failed to establish a new connection: [Errno -3] Temporary failure in name resolution')': /simple/sanic/
WARNING: Retrying (Retry(total=2, connect=None, read=None, redirect=None, status=None)) after connection broken by 'NewConnectionError('<pip._vendor.urllib3.connection.HTTPSConnection object at 0x7fbe9ee1d750>: Failed to establish a new connection: [Errno -3] Temporary failure in name resolution')': /simple/sanic/
WARNING: Retrying (Retry(total=1, connect=None, read=None, redirect=None, status=None)) after connection broken by 'NewConnectionError('<pip._vendor.urllib3.connection.HTTPSConnection object at 0x7fbe9ee1db10>: Failed to establish a new connection: [Errno -3] Temporary failure in name resolution')': /simple/sanic/
WARNING: Retrying (Retry(total=0, connect=None, read=None, redirect=None, status=None)) after connection broken by 'NewConnectionError('<pip._vendor.urllib3.connection.HTTPSConnection object at 0x7fbe9ee1ded0>: Failed to establish a new connection: [Errno -3] Temporary failure in name resolution')': /simple/sanic/

解决:

service docker restart

演示:

 

[root@test1 service1]# service docker restart
Redirecting to /bin/systemctl restart docker.service

[root@test1 service1]# docker build -t test_nfs:1.0 .
Sending build context to Docker daemon 3.584kB
Step 1/4 : FROM python:3.7
---> 9337bc3e7477
Step 2/4 : RUN ln -sf /usr/share/zoneinfo/Asia/Shanghai /etc/localtime && echo "Asia/Shanghai" > /etc/timezone && pip install -i https://pypi.tuna.tsinghua.edu.cn/simple/ sanic==18.12.0 requests==2.20.0
---> Running in 6e47974b792a
Looking in indexes: https://pypi.tuna.tsinghua.edu.cn/simple/
Collecting sanic==18.12.0
Downloading https://pypi.tuna.tsinghua.edu.cn/packages/11/b1/96424ff7d7d53b45adda69ac5306b58f349d1b7a937430aeb397f61452be/sanic-18.12.0-py3-none-any.whl (52 kB)
Collecting requests==2.20.0
Downloading https://pypi.tuna.tsinghua.edu.cn/packages/f1/ca/10332a30cb25b627192b4ea272c351bce3ca1091e541245cccbace6051d8/requests-2.20.0-py2.py3-none-any.whl (60 kB)
Collecting urllib3<1.25,>=1.21.1
Downloading https://pypi.tuna.tsinghua.edu.cn/packages/01/11/525b02e4acc0c747de8b6ccdab376331597c569c42ea66ab0a1dbd36eca2/urllib3-1.24.3-py2.py3-none-any.whl (118 kB)
Collecting certifi>=2017.4.17
Downloading https://pypi.tuna.tsinghua.edu.cn/packages/5e/a0/5f06e1e1d463903cf0c0eebeb751791119ed7a4b3737fdc9a77f1cdfb51f/certifi-2020.12.5-py2.py3-none-any.whl (147 kB)
Collecting idna<2.8,>=2.5
Downloading https://pypi.tuna.tsinghua.edu.cn/packages/4b/2a/0276479a4b3caeb8a8c1af2f8e4355746a97fab05a372e4a2c6a6b876165/idna-2.7-py2.py3-none-any.whl (58 kB)
Collecting chardet<3.1.0,>=3.0.2
Downloading https://pypi.tuna.tsinghua.edu.cn/packages/bc/a9/01ffebfb562e4274b6487b4bb1ddec7ca55ec7510b22e4c51f14098443b8/chardet-3.0.4-py2.py3-none-any.whl (133 kB)
Collecting multidict<5.0,>=4.0
Downloading https://pypi.tuna.tsinghua.edu.cn/packages/85/b8/a9fe777dab4c6aa067b516a34fe995213707e490ea1e72f823949a830a6a/multidict-4.7.6-cp37-cp37m-manylinux1_x86_64.whl (149 kB)
Collecting websockets<7.0,>=6.0
Downloading https://pypi.tuna.tsinghua.edu.cn/packages/0c/6a/d048dfe820fc956e57bb1115f5eda5a1bef320172811f72c9924c8d6ebb5/websockets-6.0-cp37-cp37m-manylinux1_x86_64.whl (88 kB)
Collecting aiofiles>=0.3.0
Downloading https://pypi.tuna.tsinghua.edu.cn/packages/ba/21/df5eae4b6db2eb00d58428dd7f793ecbf99942fcafcea141cbf108fa72f4/aiofiles-0.6.0-py3-none-any.whl (11 kB)
Collecting httptools>=0.0.10
Downloading https://pypi.tuna.tsinghua.edu.cn/packages/4c/87/ebb92639705924aac5ed6aa91bd4332b20d7180f3e94bd168742e7671025/httptools-0.2.0-cp37-cp37m-manylinux1_x86_64.whl (344 kB)
Collecting uvloop>=0.5.3
Downloading https://pypi.tuna.tsinghua.edu.cn/packages/87/05/805df4850d9659efd69d00076269ae6adcb0e151d1922cff822ead2c432a/uvloop-0.15.2-cp37-cp37m-manylinux2010_x86_64.whl (3.8 MB)
Collecting ujson>=1.35
Downloading https://pypi.tuna.tsinghua.edu.cn/packages/17/4e/50e8e4cf5f00b537095711c2c86ac4d7191aed2b4fffd5a19f06898f6929/ujson-4.0.2-cp37-cp37m-manylinux1_x86_64.whl (179 kB)
Installing collected packages: websockets, uvloop, urllib3, ujson, multidict, idna, httptools, chardet, certifi, aiofiles, sanic, requests
Successfully installed aiofiles-0.6.0 certifi-2020.12.5 chardet-3.0.4 httptools-0.2.0 idna-2.7 multidict-4.7.6 requests-2.20.0 sanic-18.12.0 ujson-4.0.2 urllib3-1.24.3 uvloop-0.15.2 websockets-6.0
Removing intermediate container 6e47974b792a
---> 2ad23752c36b
Step 3/4 : ADD *.py /root/
---> 558b49bd161f
Step 4/4 : CMD sh -c "python -u /root/test.py 1>>/root/nfs_root/test.log 2>>/root/nfs_root/test.err"
---> Running in 585d9860afbc
Removing intermediate container 585d9860afbc
---> 1c62ba9e6135
Successfully built 1c62ba9e6135
Successfully tagged test_nfs:1.0

 

 

posted on 2021-05-11 14:49  不要挡着我晒太阳  阅读(1838)  评论(0编辑  收藏  举报

导航