| # Dockerfile |
|
|
| FROM python:3.10-slim |
|
|
| WORKDIR /app |
|
|
| COPY requirements.txt . |
| RUN pip install --no-cache-dir -r requirements.txt |
|
|
| COPY . . |
|
|
| ##CMD ["python", "app.py"] |
|
|
| ##以下是新增的配置啟動 Gunicorn 否則可刪除指運行以上 |
|
|
| # 切換到 Hugging Face 預設的非 root 用戶 (UID 1000) |
| RUN useradd -m -u 1000 user |
| USER user |
| ENV HOME=/home/user \ |
| PATH=/home/user/.local/bin:$PATH |
|
|
| # 核心配置:啟動 Gunicorn |
| ##CMD ["gunicorn", "-k", "gevent", "-w", "4", "-b", "0.0.0.0:7860", "app:app"] |
| ##CMD ["gunicorn", "-k", "gevent", "-w", "4", "--access-logfile", "-", "--error-logfile", "-", "--timeout", "120", "-b", "0.0.0.0:7860", "app:app"] |
| CMD ["gunicorn", "-w", "1", "-b", "0.0.0.0:7860", "--log-level", "warning", "--capture-output", "--access-logfile", "-", "--error-logfile", "-", "app:app"] |
| ##CMD ["gunicorn", "-w", "1", "-b", "0.0.0.0:7860", "--preload", "--log-level", "debug", "--capture-output", "--access-logfile", "-", "--error-logfile", "-", "app:app"] |