A super fast on demand local PyPi mirror
Target users / conditions
Company / Enterprise / Small team, members of which use Python and utlize pip for package management. Although there're lots of PyPi mirrors, the download speed is limited to the bandwidth, which brings unnecessary time when a same package been downloaded by multiple users, specially for some large packages.
When you use docker for building different Python-based application / environment, perhaps you would delete previous built image and test the Dockerfile over and over again. And adjust the commands in Dockerfile would also cause the cached intermediate container to be invalid. Re-downloading packages from PyPi (or its mirrors) takes unnecessary time.
Please see this post on my blog.
The nginx configuration file
overlay/etc/nginx/sites-available/default is configurated for caching
https://pypi.tuna.tsinghua.edu.cn/simple, you may modify it if you prefer another PyPi repo.
- Get a domain name and its SSL certificates.
- Put the SSL certificate to
overlay/cert/pypi.crt, and the private key to
sudo docker volume create pypicache sudo docker build -t pip-cache ./
sudo docker run -d \ -p 443:443 \ --mount source=pypicache,target=/srv/pypicache/data \ --name pypicache \ pip-cache
pip3 install -i https://pypi.yourdomain.com/simple anypackage