FROM python:3.9-slim # 创建专用用户 RUN useradd -m -u 1000 appuser # 设置工作目录 WORKDIR /app # 安装系统依赖 RUN apt-get update && apt-get install -y --no-install-recommends \ gcc python3-dev && \ rm -rf /var/lib/apt/lists/* # 全局安装依赖 COPY requirements.txt . RUN pip install --no-cache-dir -r requirements.txt # 设置权限 RUN chown -R appuser:appuser /app USER appuser # 复制代码 COPY --chown=appuser:appuser . . # 设置容器入口 ENTRYPOINT ["uvicorn", "app:app", "--host", "0.0.0.0", "--port", "7860"]