Browse Source

国内优化

黄中银 3 months ago
parent
commit
1aa52e590b
2 changed files with 19 additions and 1 deletions
  1. 2 0
      cognio/buildDockerImage_u24_docker.ps1
  2. 17 1
      cognio/国内构建详解.md

+ 2 - 0
cognio/buildDockerImage_u24_docker.ps1

@@ -100,6 +100,8 @@ echo "添加 apt 国内镜像源..."
 sed -i '/^FROM/a RUN sed -i "s|http://deb.debian.org|https://mirrors.aliyun.com|g" /etc/apt/sources.list.d/debian.sources 2>/dev/null || sed -i "s|http://deb.debian.org|https://mirrors.aliyun.com|g" /etc/apt/sources.list 2>/dev/null || true' Dockerfile
 sed -i '/^FROM/a RUN sed -i "s|http://deb.debian.org|https://mirrors.aliyun.com|g" /etc/apt/sources.list.d/debian.sources 2>/dev/null || sed -i "s|http://deb.debian.org|https://mirrors.aliyun.com|g" /etc/apt/sources.list 2>/dev/null || true' Dockerfile
 echo "配置 pip 国内镜像源..."
 echo "配置 pip 国内镜像源..."
 sed -i 's|pip install|pip install -i https://mirrors.aliyun.com/pypi/simple/ --trusted-host mirrors.aliyun.com|g' Dockerfile
 sed -i 's|pip install|pip install -i https://mirrors.aliyun.com/pypi/simple/ --trusted-host mirrors.aliyun.com|g' Dockerfile
+echo "配置 Poetry 国内镜像源..."
+sed -i '/^FROM/a RUN mkdir -p /root/.config/pip \&\& printf "[global]\\nindex-url = https://mirrors.aliyun.com/pypi/simple/\\ntrusted-host = mirrors.aliyun.com\\n" > /root/.config/pip/pip.conf' Dockerfile
 echo "正在构建并推送 Docker 镜像..."
 echo "正在构建并推送 Docker 镜像..."
 echo "使用镜像加速: $dockerMirror"
 echo "使用镜像加速: $dockerMirror"
 docker buildx build \
 docker buildx build \

+ 17 - 1
cognio/国内构建详解.md

@@ -83,7 +83,7 @@ $tmuxSession = "dbx"
 
 
 ## 国内加速优化
 ## 国内加速优化
 
 
-脚本会自动修改 Dockerfile,应用以下项国内加速:
+脚本会自动修改 Dockerfile,应用以下项国内加速:
 
 
 ### 1. Docker 基础镜像加速
 ### 1. Docker 基础镜像加速
 
 
@@ -121,22 +121,38 @@ pip install -i https://mirrors.aliyun.com/pypi/simple/ --trusted-host mirrors.al
 
 
 **实现方式**:使用 `sed` 全局替换 Dockerfile 中的 `pip install`。
 **实现方式**:使用 `sed` 全局替换 Dockerfile 中的 `pip install`。
 
 
+### 4. Poetry 源加速(阿里云)
+
+通过创建全局 pip 配置文件,让 Poetry 底层下载包时也使用阿里云源:
+
+```bash
+# 在 Dockerfile 中插入
+RUN mkdir -p /root/.config/pip && printf "[global]\nindex-url = https://mirrors.aliyun.com/pypi/simple/\ntrusted-host = mirrors.aliyun.com\n" > /root/.config/pip/pip.conf
+```
+
+**实现方式**:在 `FROM` 行后插入创建 pip 配置文件的 `RUN` 命令。
+
 ## Dockerfile 修改示例
 ## Dockerfile 修改示例
 
 
 原始 Dockerfile:
 原始 Dockerfile:
+
 ```dockerfile
 ```dockerfile
 FROM python:3.11-slim
 FROM python:3.11-slim
 RUN apt-get update && apt-get install -y gcc
 RUN apt-get update && apt-get install -y gcc
 RUN pip install poetry==1.7.1
 RUN pip install poetry==1.7.1
+RUN poetry install
 ```
 ```
 
 
 修改后:
 修改后:
+
 ```dockerfile
 ```dockerfile
 ARG DOCKER_MIRROR=docker.io
 ARG DOCKER_MIRROR=docker.io
 FROM ${DOCKER_MIRROR}/library/python:3.11-slim
 FROM ${DOCKER_MIRROR}/library/python:3.11-slim
+RUN mkdir -p /root/.config/pip && printf "[global]\nindex-url = https://mirrors.aliyun.com/pypi/simple/\ntrusted-host = mirrors.aliyun.com\n" > /root/.config/pip/pip.conf
 RUN sed -i "s|http://deb.debian.org|https://mirrors.aliyun.com|g" /etc/apt/sources.list.d/debian.sources 2>/dev/null || true
 RUN sed -i "s|http://deb.debian.org|https://mirrors.aliyun.com|g" /etc/apt/sources.list.d/debian.sources 2>/dev/null || true
 RUN apt-get update && apt-get install -y gcc
 RUN apt-get update && apt-get install -y gcc
 RUN pip install -i https://mirrors.aliyun.com/pypi/simple/ --trusted-host mirrors.aliyun.com poetry==1.7.1
 RUN pip install -i https://mirrors.aliyun.com/pypi/simple/ --trusted-host mirrors.aliyun.com poetry==1.7.1
+RUN poetry install
 ```
 ```
 
 
 ## 查看构建进度
 ## 查看构建进度