Dockerfile 1.8 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465
  1. FROM nvidia/cuda:12.4.1-devel-ubuntu22.04
  2. ENV DEBIAN_FRONTEND=noninteractive
  3. ENV PYTHONUNBUFFERED=1
  4. ENV GRADIO_SERVER_NAME=0.0.0.0
  5. ENV GRADIO_SERVER_PORT=7860
  6. # System dependencies
  7. RUN apt-get update && apt-get install -y --no-install-recommends \
  8. python3.11 \
  9. python3.11-venv \
  10. python3.11-dev \
  11. python3-pip \
  12. git \
  13. git-lfs \
  14. wget \
  15. curl \
  16. build-essential \
  17. && rm -rf /var/lib/apt/lists/* \
  18. && git lfs install
  19. # Set python3.11 as default
  20. RUN update-alternatives --install /usr/bin/python3 python3 /usr/bin/python3.11 1 \
  21. && update-alternatives --install /usr/bin/python python /usr/bin/python3.11 1
  22. # Upgrade pip
  23. RUN python -m pip install --no-cache-dir --upgrade pip setuptools wheel
  24. # Install PyTorch with CUDA 12.4
  25. RUN pip install --no-cache-dir torch torchvision torchaudio --index-url https://download.pytorch.org/whl/cu124
  26. # Install Unsloth (bundles transformers, peft, trl, bitsandbytes, xformers etc.)
  27. RUN pip install --upgrade --force-reinstall --no-cache-dir unsloth unsloth_zoo
  28. # Create non-root user FIRST
  29. RUN useradd -m -u 1000 user
  30. # Create app directory
  31. WORKDIR /app
  32. # Copy requirements and install remaining deps
  33. COPY requirements.txt .
  34. RUN pip install --no-cache-dir -r requirements.txt
  35. # Copy app files
  36. COPY . .
  37. # Create ALL directories under user home (NOT /tmp)
  38. RUN mkdir -p /home/user/hf_cache /home/user/torch_cache /home/user/output /home/user/merged \
  39. && chown -R user:user /home/user /app
  40. # Set cache env vars to user home
  41. ENV HOME=/home/user
  42. ENV HF_HOME=/home/user/hf_cache
  43. ENV TRANSFORMERS_CACHE=/home/user/hf_cache
  44. ENV TORCH_HOME=/home/user/torch_cache
  45. ENV PATH="/home/user/.local/bin:$PATH"
  46. # Limit PyTorch CUDA memory fragmentation and allow expandable segments
  47. ENV PYTORCH_CUDA_ALLOC_CONF=expandable_segments:True
  48. USER user
  49. EXPOSE 7860
  50. CMD ["python", "app.py"]