Spaces:
Runtime error
Runtime error
Update Dockerfile
Browse files- Dockerfile +18 -14
Dockerfile
CHANGED
|
@@ -1,33 +1,37 @@
|
|
| 1 |
-
# Use official Python image
|
| 2 |
-
FROM python:3.9-slim
|
| 3 |
|
| 4 |
# Set environment variables
|
| 5 |
-
ENV PYTHONDONTWRITEBYTECODE
|
| 6 |
-
|
| 7 |
-
|
| 8 |
-
|
|
|
|
| 9 |
|
| 10 |
# Set work directory
|
| 11 |
WORKDIR /app
|
| 12 |
|
| 13 |
-
# Install system dependencies
|
| 14 |
-
RUN apt-get update && apt-get install -y \
|
| 15 |
build-essential \
|
| 16 |
&& rm -rf /var/lib/apt/lists/*
|
| 17 |
|
| 18 |
-
#
|
| 19 |
COPY requirements.txt .
|
|
|
|
|
|
|
| 20 |
RUN pip install --no-cache-dir -r requirements.txt
|
| 21 |
|
| 22 |
-
# Copy
|
| 23 |
COPY . .
|
| 24 |
|
| 25 |
-
# Create non-root user and
|
| 26 |
-
RUN useradd -m myuser &&
|
|
|
|
| 27 |
USER myuser
|
| 28 |
|
| 29 |
# Expose port
|
| 30 |
EXPOSE 8000
|
| 31 |
|
| 32 |
-
# Run application
|
| 33 |
-
CMD ["gunicorn", "--bind", "0.0.0.0:8000", "app:app"]
|
|
|
|
| 1 |
+
# Use official Python image with slim-buster base
|
| 2 |
+
FROM python:3.9-slim-buster
|
| 3 |
|
| 4 |
# Set environment variables
|
| 5 |
+
ENV PYTHONDONTWRITEBYTECODE=1 \
|
| 6 |
+
PYTHONUNBUFFERED=1 \
|
| 7 |
+
HF_HOME=/app/cache \
|
| 8 |
+
HUGGINGFACE_HUB_DISABLE_XET=1 \
|
| 9 |
+
PIP_NO_CACHE_DIR=1
|
| 10 |
|
| 11 |
# Set work directory
|
| 12 |
WORKDIR /app
|
| 13 |
|
| 14 |
+
# Install only essential system dependencies
|
| 15 |
+
RUN apt-get update && apt-get install -y --no-install-recommends \
|
| 16 |
build-essential \
|
| 17 |
&& rm -rf /var/lib/apt/lists/*
|
| 18 |
|
| 19 |
+
# Copy only requirements first to leverage Docker cache
|
| 20 |
COPY requirements.txt .
|
| 21 |
+
|
| 22 |
+
# Install Python dependencies with pip
|
| 23 |
RUN pip install --no-cache-dir -r requirements.txt
|
| 24 |
|
| 25 |
+
# Copy application files
|
| 26 |
COPY . .
|
| 27 |
|
| 28 |
+
# Create non-root user and set permissions
|
| 29 |
+
RUN useradd -m myuser && \
|
| 30 |
+
chown -R myuser:myuser /app
|
| 31 |
USER myuser
|
| 32 |
|
| 33 |
# Expose port
|
| 34 |
EXPOSE 8000
|
| 35 |
|
| 36 |
+
# Run application with Gunicorn
|
| 37 |
+
CMD ["gunicorn", "--bind", "0.0.0.0:8000", "--workers", "2", "app:app"]
|