FROM python:3.11-slim WORKDIR /app # Install system dependencies RUN apt-get update && apt-get install -y --no-install-recommends \ gcc \ libpq-dev \ && apt-get clean \ && rm -rf /var/lib/apt/lists/* # Copy requirements first for better caching COPY requirements.txt . # Upgrade pip and install dependencies RUN pip install --upgrade pip && \ pip install -r requirements.txt # Copy the rest of the application COPY . . # Create a non-root user to run the app RUN useradd -m appuser && \ chown -R appuser:appuser /app USER appuser # Set environment variables ENV PYTHONDONTWRITEBYTECODE=1 \ PYTHONUNBUFFERED=1 # Run gunicorn CMD ["gunicorn", "--bind", "0.0.0.0:8000", "--workers", "4", "wsgi:app"]