# Use Python 3.11 slim image for a smaller footprint FROM python:3.11-slim # Set environment variables ENV PYTHONDONTWRITEBYTECODE=1 \ PYTHONUNBUFFERED=1 \ PIP_NO_CACHE_DIR=1 \ PIP_DISABLE_PIP_VERSION_CHECK=1 \ HOME=/home/appuser \ APP_HOME=/home/appuser/app # Create non-root user and setup directories RUN groupadd -g 1000 appgroup && \ useradd -m -u 1000 -g appgroup -s /bin/bash -d ${HOME} appuser && \ mkdir -p ${APP_HOME} && \ mkdir -p ${APP_HOME}/data && \ chown -R appuser:appgroup ${HOME} # Set the working directory WORKDIR ${APP_HOME} # Install dependencies COPY --chown=appuser:appgroup requirements.txt ${APP_HOME}/ RUN pip install --no-cache-dir -r requirements.txt # Copy application code COPY --chown=appuser:appgroup . ${APP_HOME}/ # Switch to non-root user USER appuser # Expose port EXPOSE 8000 # Command to run the application CMD ["uvicorn", "main:app", "--host", "0.0.0.0", "--port", "8000"]