# 1. Pulls a pre-compiled Linux image with Python 3.9 installed into the container FROM python:3.9 # 2. Creates a non-root user (ID 1000) for security compliance on Hugging Face servers RUN useradd -m -u 1000 user # 3. Switches the active execution context to this new user USER user # 4. Sets environment variables defining the user's home directory and executable paths ENV HOME=/home/user \ PATH=/home/user/.local/bin:$PATH # 5. Sets the active working directory where subsequent commands will execute WORKDIR $HOME/app # 6. Copies the requirements file from the Git repo into the container's file system COPY --chown=user ./requirements.txt $HOME/app/requirements.txt # 7. Triggers the package manager to download and install libraries into the container's RAM/Disk RUN pip install --no-cache-dir --upgrade -r $HOME/app/requirements.txt # 8. Copies your app.py (and any other files) into the container COPY --chown=user . $HOME/app # 9. Starts the server process. Routes all data flowing to 0.0.0.0:7860 into the FastAPI application CMD ["uvicorn", "app:app", "--host", "0.0.0.0", "--port", "7860"]