# Use an official Python runtime as a parent image FROM python:3.10-slim # Set the working directory in the container WORKDIR /code # Set environment variables - ALL EPHEMERAL CACHING (no persistent storage) # All caches in fast /tmp/ storage (cleared on restart - prevents future bloat) ENV TRANSFORMERS_CACHE="/tmp/transformers_cache" ENV HF_HOME="/tmp/hf_cache" ENV MPLCONFIGDIR="/tmp/matplotlib_cache" ENV TORCH_HOME="/tmp/torch_cache" ENV PYTORCH_KERNEL_CACHE_PATH="/tmp/torch_kernels" # PyTorch CUDA memory allocation optimization ENV PYTORCH_CUDA_ALLOC_CONF="expandable_segments:True" # Copy and install dependencies FIRST (for better caching) COPY requirements.txt . RUN pip install --no-cache-dir --upgrade pip && \ pip install --no-cache-dir --trusted-host pypi.python.org -r requirements.txt # Copy application code LAST COPY . . CMD ["python", "app.py"]