# Use a slim Python image for smaller size and faster downloads FROM python:3.9-slim # Set environment variables for non-interactive commands ENV DEBIAN_FRONTEND=noninteractive ENV PYTHONUNBUFFERED=1 # --- NEW LINE: Set Hugging Face cache directory --- # This ensures that the user inside the container has write permissions for the cache. ENV HF_HOME="/tmp/.cache/huggingface" # Set the working directory in the container WORKDIR /app # Install system dependencies # build-essential for compiling C extensions if needed by Python packages # libgl1-mesa-glx for PyTorch if using certain functionalities (though often not needed for CPU-only inference) # Other packages can be added as needed by your specific dependencies. RUN apt-get update && \ apt-get install -y --no-install-recommends \ build-essential \ libgl1-mesa-glx \ git \ && rm -rf /var/lib/apt/lists/* # Copy only the requirements file first to leverage Docker's build cache # This ensures that if your app code changes but dependencies don't, # the pip install step isn't re-run every time. COPY requirements.txt . # Install Python dependencies # Use --no-cache-dir to save space RUN pip install --no-cache-dir -r requirements.txt # Copy the rest of your application code and model files # This includes app.py, your model's state_dict, tokenizer files, etc. # The '.' indicates copying everything from the current host directory into the container's /app directory. COPY . . # Expose the port your FastAPI application will listen on # FastAPI typically runs on port 8000 EXPOSE 8000 # Command to run your FastAPI application using Uvicorn # 0.0.0.0 makes the server accessible from outside the container # app:app refers to the 'app' FastAPI instance within 'app.py' CMD ["uvicorn", "app:app", "--host", "0.0.0.0", "--port", "8000"]