# â’¸AngelaMos | 2025 # Production FastAPI Dockerfile # Optimized for performance with gunicorn multi-worker setup # No hot reload, built image (no volume mounts) FROM python:3.11-slim # Set environment variables ENV PYTHONUNBUFFERED=1 \ PYTHONDONTWRITEBYTECODE=1 \ PIP_NO_CACHE_DIR=1 \ PIP_DISABLE_PIP_VERSION_CHECK=1 # Set working directory WORKDIR /app # Install system dependencies RUN apt-get update && apt-get install -y --no-install-recommends \ gcc \ postgresql-client \ && rm -rf /var/lib/apt/lists/* # Copy only requirements first (for layer caching) COPY backend/requirements.txt . # Install Python dependencies RUN pip install --no-cache-dir -r requirements.txt # Install gunicorn for production RUN pip install --no-cache-dir gunicorn # Copy application code COPY backend/ . # Create non-root user for security RUN useradd -m -u 1000 appuser && chown -R appuser:appuser /app USER appuser # Expose port EXPOSE 8000 # Run with gunicorn (4 workers, uvicorn worker class for async support) CMD ["gunicorn", "main:app", \ "--workers", "4", \ "--worker-class", "uvicorn.workers.UvicornWorker", \ "--bind", "0.0.0.0:8000", \ "--access-logfile", "-", \ "--error-logfile", "-"]