# 1. Start with a CUDA-enabled base image (Required for Unsloth to utilize GPUs properly) FROM nvidia/cuda:12.1.1-cudnn8-devel-ubuntu22.04 # 2. Avoid interactive timezone/keyboard prompts during apt installation ENV DEBIAN_FRONTEND=noninteractive # 3. Install core system dependencies required by Unsloth's install.sh RUN apt-get update && apt-get install -y \ curl \ git \ python3 \ python3-pip \ python3-venv \ build-essential \ nodejs \ npm \ && rm -rf /var/lib/apt/lists/* # 4. Hugging Face Spaces require running containers as a non-root user (UID 1000) RUN useradd -m -u 1000 user USER user # 5. Set environment variables ENV HOME=/home/user # Ensure the newly installed Unsloth CLI binary is in the system PATH ENV PATH="$HOME/.local/bin:$PATH" # Point Hugging Face model cache to /data so you can use Persistent Storage without overriding the installation ENV HF_HOME=/data/huggingface WORKDIR $HOME USER root # 6. Execute the official Unsloth installation script. # This will download PyTorch, Unsloth, Node/Bun, and compile the frontend during the Docker build. RUN curl -fsSL https://unsloth.ai/install.sh | sh # 7. Expose the port we defined in our README.md EXPOSE 7860 # 8. Start the Unsloth Studio server # -H 0.0.0.0 : Binds the server to all network interfaces (required for Docker/HF Spaces) # -p 7860 : Binds it to the Hugging Face expected port CMD ["unsloth", "studio", "-H", "0.0.0.0", "-p", "7860"]