Docker安装pypiserver私服
1 简介
Python开源包管理工具有pypiserver、devpi和Nexus等,pypiserver安装部署比较简单,性能也不错。
搭建pypiserver私服,可以自己构建镜像,也可以使用官网的docker镜像。
# Github地址
https://github.com/pypiserver/pypiserver
2 安装
使用docker安装pypiserver
# 下载包
docker pull pypiserver/pypiserver:v2.3.2
使用docker安装镜像
pypiserver支持使用.htpasswd设置用户名和密码。在目录中/home/pypiserver/创建密钥文件
# Ubuntu上安装htpasswd的依赖包
sudo apt-get install apache2 apache2-utils# 生成密码文件,root是用户名(可根据需求自己设定),之后输入密码即可
htpasswd -sc /home/pypiserver/.htpasswd root# 返回值如下
New password:
Re-type new password:
Adding password for user root
创建容器
docker run -itd \
--restart always \
--name pypiserver \
-p 8080:8080 \
-v /home/pypiserver/.htpasswd:/data/.htpasswd \
-v /home/pypiserver/packages:/data/packages \
pypiserver/pypiserver:v2.3.2 run -P .htpasswd packages
访问地址
# 系统地址
http://192.168.108.146:8080/# 软件包列表
http://192.168.108.146:8080/simple/
3 下载第三方包
单个下载numpy第三方包,建议不要再容器内下载包(会在下载.tar.gz时报错),推荐在宿主机的虚拟环境中下载。
# 进入容器
docker exec -it pypiserver /bin/bash# 指定下载目录packages
pip download numpy -d ./packages --no-cache-dir# 指定第三方源,可以加快下载
pip download numpy -d ./packages -i https://pypi.tuna.tsinghua.edu.cn/simple --no-cache-dir
批量下载第三方包
pip download -r requirements.txt -d ./packages
4 使用twine上传自定义包
在Python环境中安装twine
pip install twine
上传自定义包
注意:dist目录中是打包后的tar.gz或者whl文件,
# 上传依赖包
twine upload --repository-url http://192.168.108.146:8080/ dist/*.tar.gz
twine upload --repository-url http://192.168.108.146:8080/ dist/*.whl# 返回值
twine upload --repository-url http://192.168.108.146:8080/ ./*.whl
Uploading distributions to http://192.168.108.146:8080/
Enter your username: root
Enter your password:
Uploading numpy-2.2.2-cp310-cp310-musllinux_1_2_x86_64.whl
100% ---------------------------------------- 18.2/18.2 MB • 00:00 • 174.0 MB/s
# 上传tar.gz
twine upload --repository-url http://localhost:8080 dist/numpy-2.2.2-cp310-cp310-musllinux_1_2_x86_64.tar.gz# 上传.whl
twine upload --repository-url http://localhost:8080 dist/numpy-2.2.2-cp310-cp310-musllinux_1_2_x86_64.whl
5 使用依赖包
安装私有依赖包numpy。
# 注意不能单独使用-i, --index-url安装
pip install -i http://192.168.108.146:8080/simple/ --extra-index-url http://192.168.108.146:8080/simple/ numpy# 查看numpy
pip search --index http://192.168.108.146:8080 numpy