-
服务端拉取镜像
docker pull pypiserver/pypiserver:latest
(公司内网下载不下来)
外服务器下载后docker save –o pypiserver.tar pypiserver/pypiserver:latest
将tar包上传到内网服务器,然后
docker load –i pypiserver.tar
即可得到该镜像
编辑docker-compose.yamlversion: "3.7" services: pypi-server: image: pypiserver/pypiserver hostname: pypiserver container_name: nds-pypiserver restart: always privileged: true init: true ports: - "2106:8080" volumes: - "/etc/localtime:/etc/localtime:ro" - "/home/pypiserver/packages:/data/packages"
根据Python 环境安装的库生成对应的whl文件:
import subprocess
def create_wheels_for_installed_packages():
#subprocess.run(["pip3", "install", "wheel"])
installed_packages = subprocess.run(["pip3", "list"], stdout=subprocess.PIPE)
packages_list = installed_packages.stdout.decode().split("\n")[:-1]
for package in packages_list:
print(package)
package_name = package.split()[0]
subprocess.run(["pip3", "wheel", "--wheel-dir=./", package_name])
create_wheels_for_installed_packages()
最后将这些whl文件复制到/home/pypiserver/packages/{module_name}下,启动服务
pip3 install --index-url http://yourip:yourport/simple/ uuid1 --trusted-host yourip
即可安装python库