使用devpi來搭建緩存鏡像源服務器

安裝devpi

pip install devpi-server devpi-web

啓動devpi-server

devpi-server --host=0.0.0.0 --start

默認緩存服務器使用的3141端口。再pip安裝的時候使用-i參數就能夠了

pip install -i http://localhost:3141/root/pypi/+simple/  --trusted-host localhost django
Collecting django
  Downloading http://localhost:3141/root/pypi/+f/689/2778eea81f14a/Django-1.10.5-py2.py3-none-any.whl (6.8MB)
    100% |████████████████████████████████| 6.8MB 142.8MB/s 
Installing collected packages: django
Successfully installed django-1.10.5

如今能夠看到安裝包都是從緩存代理服務器獲取,而不是每次都從pypi下載。

固然也能夠寫入配置文件這樣就不用每次都須要輸入參數

windows下python

在用戶目錄下例如C:\Users\user-admin\ 建立pip文件夾建立一個文件pip.ini
[global]
index-url = http://localhost/simple
extra-index-url=http://mirrors.aliyun.com/pypi/simple/
[install]
trusted-host = localhost mirrors.aliyun.com

Liunx下在用戶目錄建立.pip文件夾,而後在.pip文件夾建立文件pip.confweb

devpi還提供一個web界面 http://localhost:3141/docker

後面寫成一個dockerfile作成一個服務

FROM python:2.7
MAINTAINER  FenG_Vnc <z332007851@163.com>

RUN mkdir /devpi && pip install devpi-server devpi-web

EXPOSE 3141
ADD run.sh /
CMD ["/bin/bash","run.sh"]
run.sh
#!/bin/bash
set -e
set -x
export DEVPI_SERVERDIR=/devpi
[[ -f $DEVPI_SERVERDIR/.serverversion ]] || initialize=yes

if [[ $initialize = yes ]]; then
    devpi-server --port 3141 --serverdir $DEVPI_SERVERDIR --init
fi

devpi-server --host 0.0.0.0 --port 3141 --serverdir $DEVPI_SERVERDIR
docker run  -p 3141:3141 -d -it devpi  啓動docker
相關文章
相關標籤/搜索