codesearchBase / Dockerfile
Forrest99's picture
Update Dockerfile
45f0945 verified
raw
history blame
792 Bytes
# 使用轻量级基础镜像
FROM python:3.10-slim-bookworm
# 设置容器级环境变量
ENV TRANSFORMERS_CACHE=/model-cache \
HF_HOME=/model-cache \
PYTHONUNBUFFERED=1
# 安装必需的系统组件(保持root权限)
RUN apt-get update && \
apt-get install -y --no-install-recommends gcc python3-dev && \
rm -rf /var/lib/apt/lists/*
# 安装Python依赖(自动清理缓存)
COPY requirements.txt .
RUN pip install --upgrade pip && \
pip install --no-cache-dir -r requirements.txt
# 切换到非root用户
RUN useradd -m appuser && chown -R appuser /model-cache
USER appuser
# 复制应用代码
COPY app.py .
# 暴露API端口
EXPOSE 8080
# 启动命令(生产级WSGI服务器)
CMD ["gunicorn", "--bind", "0.0.0.0:8080", "--timeout", "120", "app:app"]