
pypiserver/pypiserverpypiserver是一个轻量级的PyPI兼容服务器,专为pip或easy_install设计,基于bottle框架开发,可从普通目录提供软件包服务。该Docker镜像封装了pypiserver的核心功能,支持上传/下载wheels、bdists、eggs及PGP签名文件,兼容pip、setuptools、twine等标准Python工具,无需复杂配置即可快速搭建私有PyPI仓库。
bash# 创建本地包目录 mkdir -p ~/pypi_packages # 启动基础pypiserver容器 docker run -d -p 8080:8080 -v ~/pypi_packages:/data/packages pypiserver/pypiserver:latest run -p 8080 /data/packages
创建htpasswd文件(需安装passlib):
bashpip install passlib htpasswd -sc ~/pypi_htpasswd.txt admin # 按提示输入密码
启动带认证的容器:
bashdocker run -d -p 8080:8080 \ -v ~/pypi_packages:/data/packages \ -v ~/pypi_htpasswd.txt:/data/htpasswd.txt \ pypiserver/pypiserver:latest \ run -p 8080 -P /data/htpasswd.txt -a update /data/packages
yamlversion: '3' services: pypiserver: image: pypiserver/pypiserver:latest ports: - "8080:8080" volumes: - ./packages:/data/packages - ./htpasswd.txt:/data/htpasswd.txt command: run -p 8080 -P /data/htpasswd.txt -a update,download /data/packages restart: always
| 参数 | 说明 | 示例 |
|---|---|---|
-p, --port | 服务端口 | -p 8080 |
-i, --interface | 监听地址 | -i 0.0.0.0 |
-a, --authenticate | 需要认证的操作(download/list/update) | -a update,download |
-P, --passwords | htpasswd认证文件路径 | -P /data/htpasswd.txt |
--disable-fallback | 禁用PyPI fallback | --disable-fallback |
--fallback-url | 自定义fallback地址 | --fallback-url [***] |
-o, --overwrite | 允许覆盖已存在的包 | -o |
--health-endpoint | 自定义健康检查端点 | --health-endpoint /health |
bashpip install --extra-index-url http://localhost:8080/simple/ 包名
ini[global] extra-index-url = http://localhost:8080/simple/ trusted-host = localhost # 非HTTPS时需要
ini[easy_install] index_url = http://localhost:8080/simple/
配置~/.pypirc:
ini[distutils] index-servers = local [local] repository: http://localhost:8080 username: admin # htpasswd中的用户名 password: 密码 # htpasswd中的密码
上传命令:
bashtwine upload --repository local dist/*
bashdocker run -d -p 8080:8080 \ -v ~/pypi_packages:/data/packages \ pypiserver/pypiserver:latest \ run --health-endpoint /health /data/packages
访问http://localhost:8080/health返回200 OK表示服务正常。
bashdocker run -d -p 8080:8080 \ -v ~/pypi_packages:/data/packages \ pypiserver/pypiserver:latest \ run --server-base-url /pypi /data/packages
此时访问地址为http://localhost:8080/pypi/simple/。
nginxserver { listen 80; server_name pypi.example.com; location / { proxy_pass http://localhost:8080; proxy_set_header Host $host; proxy_set_header X-Real-IP $remote_addr; } }
~/pypi_packages目录以防止数据丢失--backend cached-dir启用缓存更多详细信息请参考官方文档。
manifest unknown 错误
TLS 证书验证失败
DNS 解析超时
410 错误:版本过低
402 错误:流量耗尽
身份认证失败错误
429 限流错误
凭证保存错误
来自真实用户的反馈,见证轩辕镜像的优质服务