Dockerfile
1.18 KB
FROM python:3.11-slim
# PyPI 镜像加速(清华源)
ENV PIP_INDEX_URL=https://pypi.tuna.tsinghua.edu.cn/simple
# 运行时指定 OpenBLAS 使用最通用的内核 (Generic) 以避免 Illegal Instruction
# 之前的 PRESCOTT 可能在某些极其古老或虚拟化的 CPU 上仍有问题
ENV OPENBLAS_CORETYPE=Generic
WORKDIR /app
# 安装编译工具链(numpy 源码编译必需)
RUN apt-get update && apt-get install -y --no-install-recommends \
gcc g++ gfortran libopenblas-dev liblapack-dev \
&& rm -rf /var/lib/apt/lists/*
COPY requirements.txt .
# 从源码编译 numpy:基线 SSE3,禁止 dispatch
RUN pip install --no-cache-dir --no-binary=numpy numpy==1.26.4 \
-Csetup-args=-Dcpu-baseline=sse3 \
-Csetup-args=-Dcpu-dispatch=none
RUN pip install --no-cache-dir -r requirements.txt
# 验证关键库是否能正常导入(在构建阶段提前暴露 SIGILL 或 缺失依赖)
RUN python -c "import numpy; print('numpy:', numpy.__version__)"
RUN python -c "import pandas; print('pandas:', pandas.__version__)"
RUN python -c "import pydantic_core; print('pydantic-core OK')"
RUN python -c "import httpx; print('httpx OK')"
COPY . .
EXPOSE 9500
CMD ["python", "main.py"]