Dockerfile 1.7 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061
  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-pip \
  11. git \
  12. git-lfs \
  13. wget \
  14. curl \
  15. && rm -rf /var/lib/apt/lists/* \
  16. && git lfs install
  17. # Set python3.11 as default
  18. RUN update-alternatives --install /usr/bin/python3 python3 /usr/bin/python3.11 1 \
  19. && update-alternatives --install /usr/bin/python python /usr/bin/python3.11 1
  20. # Upgrade pip
  21. RUN python -m pip install --no-cache-dir --upgrade pip setuptools wheel
  22. # Install PyTorch with CUDA 12.4
  23. RUN pip install --no-cache-dir torch torchvision torchaudio --index-url https://download.pytorch.org/whl/cu124
  24. # Install flash-attention for faster training
  25. RUN pip install --no-cache-dir flash-attn --no-build-isolation 2>/dev/null || echo "Flash attention build failed, continuing without it"
  26. # Create non-root user FIRST
  27. RUN useradd -m -u 1000 user
  28. # Create app directory
  29. WORKDIR /app
  30. # Copy requirements and install
  31. COPY requirements.txt .
  32. RUN pip install --no-cache-dir -r requirements.txt
  33. # Copy app files
  34. COPY . .
  35. # Create ALL directories under user home (NOT /tmp)
  36. RUN mkdir -p /home/user/hf_cache /home/user/torch_cache /home/user/output /home/user/merged \
  37. && chown -R user:user /home/user /app
  38. # Set cache env vars to user home
  39. ENV HOME=/home/user
  40. ENV HF_HOME=/home/user/hf_cache
  41. ENV TRANSFORMERS_CACHE=/home/user/hf_cache
  42. ENV TORCH_HOME=/home/user/torch_cache
  43. ENV PATH="/home/user/.local/bin:$PATH"
  44. USER user
  45. EXPOSE 7860
  46. CMD ["python", "app.py"]