個人在配置完環境后,發現需要升級pip和安裝幾十個依賴包,在build的過程中,下載經常會出現下載很慢和超時的情況,導致需要去刪除鏡像再重新開始,很浪費時間,后面發現可以Dockerfile執行命令上加上-i,及下載源鏈接,包括pip升級和安裝依賴包都可以的,代碼如下:
# 升級pip
RUN pip install --upgrade pip -i https://mirrors.aliyun.com/pypi/simple/
# 安裝依賴包
RUN pip install -r requirements.txt -i https://mirrors.aliyun.com/pypi/simple/
國內的下載源有以下這些:
1.阿里雲
http://mirrors.aliyun.com/pypi/simple/
2.中國科技大學
https://pypi.mirrors.ustc.edu.cn/simple/
3.豆瓣(douban)
http://pypi.douban.com/simple/
4.清華大學
https://pypi.tuna.tsinghua.edu.cn/simple/
5.中國科學技術大學
http://pypi.mirrors.ustc.edu.cn/simple/