# Use Python 3.11 slim as base image | |
FROM python:3.11-slim | |
# Set environment variables | |
ENV PYTHONDONTWRITEBYTECODE=1 \ | |
PYTHONUNBUFFERED=1 | |
# Set work directory | |
WORKDIR /app | |
# Copy requirements and install dependencies | |
COPY requirements.txt . | |
RUN pip install --no-cache-dir -r requirements.txt | |
# Copy the application | |
COPY ./app ./app | |
COPY ./data ./data | |
# Create non-root user | |
RUN adduser --disabled-password --gecos "" appuser \ | |
&& chown -R appuser:appuser /app | |
# Switch to non-root user | |
USER appuser | |
# Expose port | |
EXPOSE 8000 | |
# Command to run the application | |
CMD ["uvicorn", "app.main:app", "--host", "0.0.0.0", "--port", "7860"] |