打包镜像并上传到 Harbor
# 安装 docker
apt install docker.io
# 拉取代码
git clone http://gitea.dtdream.vip/z1459/pypa_proxy.git
cd pypa_proxy
# 打包镜像
docker build -t pypa_proxy .
# 查看镜像id并设置tag
docker images
docker tag 6aed41d6387d 10.10.140.105:80/library/pypa_proxy:v1.0
# 登陆 Harbor 并推送本地镜像
docker login 10.10.140.105:80
docker push 10.10.140.105:80/library/pypa_proxy:v1.0
从 Harbor 拉取镜像并启动容器
# 从Harbor拉取镜像
docker pull 10.10.140.105:80/library/pypa_proxy:v1.0
# 通过拉取的镜像启动容器
docker run -d -p 8082:8080 --name pypa -v /data/pypa_proxy:/pypa_proxy/data 10.10.140.105:80/library/pypa_proxy:v1.0
报错处理
Harbor 部署在内网时通过非https方式访问时需要在配置文件中信任Harbor地址
# 报错内容
# Error response from daemon: Get "https://10.10.140.105:80/v2/": http: server gave HTTP response to HTTPS client
# 添加 insecure-registries 配置,无 daemon.json 文件时需手动创建 daemon.json 文件。
vim /etc/docker/daemon.json
{
"registry-mirror": [
"http://10.10.140.105:80",
"https://ung2thfc.mirror.aliyuncs.com",
"https://docker.mirrors.ustc.edu.cn",
"http://hub-mirror.c.163.com"
],
"insecure-registries": [
"10.10.140.105:80"
]
}
# 重启 docker 服务
systemctl daemon-reload && systemctl restart docker
镜像功能验证
# 设置 pip 代理并信任
pip config set global.trusted-host pypa.dtdream.vip
pip config set global.index-url http://pypa.dtdream.vip/pypi
pip config set global.trusted-host 10.10.140.113
pip config set global.index-url http://10.10.140.113:8082/pypi
# 创建并启用虚拟环境
python3 -m venv venv
source venv/bin/active
# 使用pip安装依赖
pip install xlrd
pip install redis