From 2258b8825f9fee659eaafbae1e13530c81ddf9cb Mon Sep 17 00:00:00 2001 From: Paul Zhu Date: Sun, 14 Jan 2024 07:33:42 +0800 Subject: [PATCH] fix: docker imge issues #419 #425 (#426) * fix: docker imge issues #419 #425 * feat(docker): allow external PIP_INDEX_URL via build-arg --- Dockerfile | 7 +++++-- README.md | 6 ++++++ 2 files changed, 11 insertions(+), 2 deletions(-) diff --git a/Dockerfile b/Dockerfile index e139a844..53d0f8c9 100644 --- a/Dockerfile +++ b/Dockerfile @@ -1,7 +1,10 @@ FROM python:3.10 AS builder WORKDIR /app COPY requirements.txt . -RUN python3 -m venv .venv && .venv/bin/pip install --no-cache-dir -r requirements.txt +# 设置默认的源地址为 PyPI 官方源 +ARG PIP_INDEX_URL=https://pypi.org/simple +# 使用 ARG 定义的变量作为 pip 源地址 +RUN python3 -m venv .venv && .venv/bin/pip install --no-cache-dir -r requirements.txt -i ${PIP_INDEX_URL} FROM python:3.10-slim @@ -14,4 +17,4 @@ ENV XDG_CONFIG_HOME=/config ENV XIAOGPT_PORT=9527 VOLUME /config EXPOSE 9527 -ENTRYPOINT [".venv/bin/python3","xiaogpt.py"] +ENTRYPOINT ["/app/.venv/bin/python3", "xiaogpt.py"] diff --git a/README.md b/README.md index 958f9eba..9cbd2609 100644 --- a/README.md +++ b/README.md @@ -236,6 +236,12 @@ docker run -v :/config yihong0618/xiaogpt --config=/config/conf docker build -t xiaogpt . ``` +如果在安装依赖时构建失败或安装缓慢时,可以在构建 Docker 镜像时使用 `--build-arg` 参数来指定国内源地址: + +```sh +docker build --build-arg PIP_INDEX_URL=https://pypi.tuna.tsinghua.edu.cn/simple -t xiaogpt . +``` + 如果需要在Apple M1/M2上编译x86 ```shell