pypi-server: 1.4.2 linux: alpine3.14 python: 3.9.7
Dockerfile
FROM python:3.9.7-alpine3.14
LABEL Author="caoxiangpeng"
RUN set -ex \
# 替换国内源
&& echo "" > /root/.pypipasswd \
&& echo http://mirrors.aliyun.com/alpine/v3.14/main/ > /etc/apk/repositories \
&& echo http://mirrors.aliyun.com/alpine/v3.14/community/ >> /etc/apk/repositories \
&& apk update \
&& apk add --no-cache --virtual .build-deps gcc musl-dev libffi-dev make openssl ca-certificates libressl-dev apache2-utils\
&& pip install pypiserver; pip install passlib \
&& mkdir -p /data \
&& rm -rf /var/cache/apk/* \
&& rm -rf ~/.ash_history ~/.python_history
EXPOSE 80
VOLUME ["/data", "/root/.pypipasswd"]
# 保留此系统的编译能力,为以后安装做基础
ENTRYPOINT ["pypi-server"]
CMD ["-P", "/root/.pypipasswd", "-p", "80", "/data"]
docker 运行命令
# 当前路径
pwd
/Users/johntoms/docker/pypi-server
# 创建 数据存储目录及登录用户密码文件
mkdir packages && touch pypipasswd
# 运行 容器
docker run --name mypypi-server -v <pwd>/pacakages:/data -v <pwd>/pypipasswd -p 80:80 -itd registry.cn-hangzhou.aliyuncs.com/private_app/mypypi-server-1.4.2:latest
# 添加或更新pypi用户及密码
docker exec -it mypypi-server htpasswd -b /root/.pypipasswd root PypiServer@123
本地相关配置
# ~/.pypirc
cat ~/.pypirc
[distutils]
index-servers =
install
internal
[global]
index-url =
http://127.0.0.1:2199/simple
http://pypi.douban.com/simple
[install]
trusted-host=http://127.0.0.1:2199/simple
username: root
password: <password>
[internal]
repository: http://127.0.0.1:2199
username: root
password: <password>
编译和上传本地私有包
# 在 setup.py 同级目录下,创建 package.sh
#清理数据
rm -rf dist/*
rm -rf build/*
rm -rf flask_framework.egg-info
#打包
# python3 -m pip install --upgrade setuptools wheel
python3 setup.py sdist bdist_wheel
# 上传
python setup.py sdist register -r local upload -r local
运行脚本
sh package.sh
安装
# --extral-index-url
pip install flask_framework --extral-index-url http://127.0.0.1:2199/simple
# -i
pip install flask_framework -i install