Update Dockerfile
Browse files- Dockerfile +20 -12
Dockerfile
CHANGED
|
@@ -1,19 +1,27 @@
|
|
| 1 |
# Base image: CPU-only Python 3.12
|
| 2 |
FROM python:3.12-slim
|
| 3 |
|
| 4 |
-
#
|
| 5 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
| 6 |
|
| 7 |
-
#
|
| 8 |
-
|
| 9 |
-
COPY app.py .
|
| 10 |
|
| 11 |
-
#
|
| 12 |
-
|
| 13 |
-
RUN pip install --
|
|
|
|
| 14 |
|
| 15 |
-
#
|
| 16 |
-
|
| 17 |
|
| 18 |
-
#
|
| 19 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
# Base image: CPU-only Python 3.12
|
| 2 |
FROM python:3.12-slim
|
| 3 |
|
| 4 |
+
# Create a non-root user (UID 1000 is required by Hugging Face)
|
| 5 |
+
RUN useradd -m -u 1000 user
|
| 6 |
+
USER user
|
| 7 |
+
ENV HOME=/home/user \
|
| 8 |
+
PATH=/home/user/.local/bin:$PATH \
|
| 9 |
+
HF_HOME=/home/user/huggingface
|
| 10 |
|
| 11 |
+
# Set working directory to the user's home
|
| 12 |
+
WORKDIR $HOME/app
|
|
|
|
| 13 |
|
| 14 |
+
# Copy and install dependencies first (for better caching)
|
| 15 |
+
COPY --chown=user requirements.txt .
|
| 16 |
+
RUN pip install --upgrade pip && \
|
| 17 |
+
pip install --no-cache-dir -r requirements.txt
|
| 18 |
|
| 19 |
+
# Copy application code
|
| 20 |
+
COPY --chown=user app.py .
|
| 21 |
|
| 22 |
+
# Hugging Face Spaces MUST use port 7860
|
| 23 |
+
EXPOSE 7860
|
| 24 |
+
|
| 25 |
+
# Use Gunicorn with 1 worker and multiple threads for CPU LLM inference
|
| 26 |
+
# Note: 1 worker prevents loading the 1GB+ model into memory multiple times
|
| 27 |
+
CMD ["gunicorn", "--bind", "0.0.0.0:7860", "--workers", "1", "--threads", "4", "--timeout", "120", "app:app"]
|