Spaces:
Running
Running
File size: 1,611 Bytes
04df0fc 3aac265 04df0fc 6cc94c5 04df0fc 42ef291 04df0fc 3aac265 04df0fc 3aac265 04df0fc 3aac265 04df0fc 3aac265 04df0fc 3aac265 04df0fc |
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 39 40 41 42 43 |
# Step 1: Start with a specific, stable Python base image
FROM python:3.11-slim
# Step 2: Set environment variables for better logging and security
# Ensures Python output is sent directly to the logs, which is great for debugging.
ENV PYTHONUNBUFFERED=1
# Prevents Python from writing .pyc files, keeping the image clean.
ENV PYTHONDONTWRITEBYTECODE=1
# FIX: Sets the home directory, telling deepface to write to a permitted location.
ENV HOME=/app
# Step 3: Update, install system dependencies, and clean up in a single layer
# This installs libraries needed by OpenCV and then clears the apt cache to keep the image small.
RUN apt-get update && apt-get install -y --no-install-recommends \
libgl1 \
libglib2.0-0 \
&& rm -rf /var/lib/apt/lists/*
# Step 4: Create a non-root user for security
# Running applications as a non-root user is a critical security best practice.
RUN useradd -m appuser
# Step 5: Set the working directory
WORKDIR /app
# Step 6: Copy and install Python packages
# Copy requirements first to leverage Docker's build cache for faster builds.
COPY requirements.txt .
RUN pip install --no-cache-dir -r requirements.txt
# Step 7: Copy the rest of the application code and set permissions
COPY . .
RUN chown -R appuser:appuser /app
# Step 8: Switch to the non-root user
USER appuser
# Step 9: Expose the port the application will run on
EXPOSE 7860
# Step 10: The command to start the Gunicorn server
# Includes the long timeout for model loading and binds to the correct port.
CMD ["gunicorn", "--workers", "1", "--timeout", "120", "--bind", "0.0.0.0:7860", "app:app"] |