File size: 743 Bytes
549af91 |
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 |
# 使用Python 3.9作为基础镜像
FROM python:3.9-slim
# 创建非root用户(Hugging Face Spaces要求)
RUN useradd -m -u 1000 user
# 设置工作目录
WORKDIR /code
# 安装系统依赖
RUN apt-get update && apt-get install -y \
build-essential \
curl \
&& rm -rf /var/lib/apt/lists/*
# 复制requirements.txt
COPY --chown=user requirements.txt .
# 安装Python依赖
RUN pip install --no-cache-dir --upgrade pip && \
pip install --no-cache-dir -r requirements.txt
# 切换到非root用户
USER user
# 设置环境变量
ENV HOME=/home/user \
PATH=/home/user/.local/bin:$PATH \
PYTHONPATH=/code
# 复制应用代码
COPY --chown=user . .
# 暴露端口
EXPOSE 7860
# 启动服务
CMD ["python", "app.py"] |