Dockerfile 1.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263
  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 flash-attention for faster training
  27. RUN pip install --no-cache-dir flash-attn --no-build-isolation 2>/dev/null || echo "Flash attention build failed, continuing without it"
  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
  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. USER user
  47. EXPOSE 7860
  48. CMD ["python", "app.py"]