|
|
@@ -123,14 +123,14 @@ pip install -i https://mirrors.aliyun.com/pypi/simple/ --trusted-host mirrors.al
|
|
|
|
|
|
### 4. Poetry 源加速(阿里云)
|
|
|
|
|
|
-通过创建全局 pip 配置文件,让 Poetry 底层下载包时也使用阿里云源:
|
|
|
+通过环境变量配置 pip 源,让 Poetry 解析和下载依赖时都使用阿里云源:
|
|
|
|
|
|
-```bash
|
|
|
+```dockerfile
|
|
|
# 在 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
|
|
|
+ENV PIP_INDEX_URL=https://mirrors.aliyun.com/pypi/simple/ PIP_TRUSTED_HOST=mirrors.aliyun.com
|
|
|
```
|
|
|
|
|
|
-**实现方式**:在 `FROM` 行后插入创建 pip 配置文件的 `RUN` 命令。
|
|
|
+**实现方式**:在 `FROM` 行后插入 `ENV` 指令设置环境变量。
|
|
|
|
|
|
## Dockerfile 修改示例
|
|
|
|
|
|
@@ -148,7 +148,7 @@ RUN poetry install
|
|
|
```dockerfile
|
|
|
ARG DOCKER_MIRROR=docker.io
|
|
|
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
|
|
|
+ENV PIP_INDEX_URL=https://mirrors.aliyun.com/pypi/simple/ PIP_TRUSTED_HOST=mirrors.aliyun.com
|
|
|
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 pip install -i https://mirrors.aliyun.com/pypi/simple/ --trusted-host mirrors.aliyun.com poetry==1.7.1
|