| # Use a slim Python image | |
| FROM python:3.10-slim | |
| # Add a non-root user for better security | |
| RUN useradd user | |
| USER user | |
| # Set environment variables | |
| ENV HOME=/home/user \ | |
| PATH=/home/user/.local/bin:$PATH | |
| # Set the working directory | |
| WORKDIR $HOME/app | |
| # Copy application files and set ownership to the non-root user | |
| COPY --chown=user ./ $HOME/app | |
| # Install Python dependencies | |
| RUN pip install --no-cache-dir -r requirements.txt | |
| # Expose the port for FastAPI (default is 7860 as per your requirement) | |
| EXPOSE 7860 | |
| # Command to start FastAPI with uvicorn, listening on port 7860 | |
| CMD ["uvicorn", "app:app", "--host", "0.0.0.0", "--port", "7860"] | |