Skip to content

PanicTitan/ComfyUI-Setup

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

4 Commits
 
 
 
 
 
 

Repository files navigation

Local AI Setup (WSL2 + Docker + Colab + ComfyUI)

⚠️ DISCLAIMER:

  • Proceed at your own risk: This guide involves system-level changes (Virtualization, Drivers, Network Ports). While tested and safe, I am not responsible for data loss or system instability.
  • Storage Warning: This setup requires approximately 60GB to 70GB of free disk space before downloading AI models. Ensure you have space!

Phase 1: Windows Preparation

Perform these steps in Command Prompt (CMD).

1. Configure Resource Limits (.wslconfig) We do this first to ensure the new installation respects your RAM limits immediately.

  1. Press Win + R, type %UserProfile%, and press Enter.
  2. Create a file named .wslconfig (ensure the file extension is not .txt).
  3. Paste the following configuration:
[wsl2]
memory=12GB
processors=4
# swap=8GB

[experimental]
sparseVhd=true
autoMemoryReclaim=gradual

memory: availible RAM.
processors: availible processor cores.
sparseVhd and autoMemoryReclaim: make the virtual disk shrinkable, freeing space when something is deleted.

2. Clean up previous installations (Optional) If you have an existing Ubuntu instance, unregister it to start fresh. Warning: This deletes all files inside Linux.

wsl --unregister Ubuntu

Tip: Check %LocalAppData%\Temp and delete wsl-crashes or large temp files to reclaim space.

3. Install WSL (Ubuntu)

wsl --install -d Ubuntu

Restart your computer if prompted. Create your username/password when the terminal opens.


Phase 2: Linux Internal Configuration

Open your Ubuntu terminal (WSL) for these steps.

1. Configure System Settings (Isolation Mode) We will disable Windows interoperability to prevent file system conflicts.

sudo nano /etc/wsl.conf

Paste exactly this: (Tip: To paste text into the Linux terminal, simply Right-Click your mouse)

[automount]
enabled = false
mountFsTab = true

[interop]
enabled = false 
appendWindowsPath = false

this settings is meant to prevent linux from easily access windows file system.

To save and exit: Press Ctrl+X, then type y, then press Enter.

2. Restart WSL to Apply Settings The new config file require a full restart of WSL to take effect.

  1. Exit from Ubuntu terminal
exit
  1. After exiting you run this on cmd (terminal) to stop WSL
wsl --shutdown
  1. Then open WSL again
wsl

3. Update System Packages

sudo apt-get update && sudo apt-get upgrade -y

Phase 3: Install Docker & NVIDIA Drivers

1. Install Docker Engine

# Add keys
sudo apt-get update
sudo apt-get install -y ca-certificates curl
sudo install -m 0755 -d /etc/apt/keyrings
sudo curl -fsSL https://download.docker.com/linux/ubuntu/gpg -o /etc/apt/keyrings/docker.asc
sudo chmod a+r /etc/apt/keyrings/docker.asc

# Add repository
echo \
  "deb [arch=$(dpkg --print-architecture) signed-by=/etc/apt/keyrings/docker.asc] https://download.docker.com/linux/ubuntu \
  $(. /etc/os-release && echo "${UBUNTU_CODENAME:-$VERSION_CODENAME}") stable" | \
  sudo tee /etc/apt/sources.list.d/docker.list > /dev/null

# Install Docker
sudo apt-get update
sudo apt-get install -y docker-ce docker-ce-cli containerd.io docker-buildx-plugin docker-compose-plugin

2. Install NVIDIA Container Toolkit

# Add repository
curl -fsSL https://nvidia.github.io/libnvidia-container/gpgkey | sudo gpg --dearmor -o /usr/share/keyrings/nvidia-container-toolkit-keyring.gpg \
  && curl -s -L https://nvidia.github.io/libnvidia-container/stable/deb/nvidia-container-toolkit.list | \
    sed 's#deb https://#deb [signed-by=/usr/share/keyrings/nvidia-container-toolkit-keyring.gpg] https://#g' | \
    sudo tee /etc/apt/sources.list.d/nvidia-container-toolkit.list

# Install toolkit
sudo apt-get update
sudo apt-get install -y nvidia-container-toolkit

# Configure and Restart
sudo nvidia-ctk runtime configure --runtime=docker
sudo systemctl restart docker

Phase 4: Create the Container

Run this once to download the image and create the container named colab_local.

# Port Mapping Explanation:
# 9000 -> 8080 (Jupyter Notebook Interface)
# 8188 -> 8188 (ComfyUI Default)
# 7865 -> 7865 (Fooocus - optional)
# 7860 -> 7860 (A1111/Forge - optional)

sudo docker run --gpus=all -d \
    -p 127.0.0.1:9000:8080 \
    -p 127.0.0.1:8188:8188 \
    -p 127.0.0.1:7865:7865 \
    -p 127.0.0.1:7860:7860 \
    --name colab_local \
    us-docker.pkg.dev/colab-images/public/runtime

Phase 5: Connect Colab to Local Machine

  1. Open your browser and go to: https://colab.research.google.com/
  2. Click New Notebook (or open your existing comfy-ui-setup.ipynb).
  3. Click the arrow next to "Connect" (top right) and select Connect to a local runtime.
  4. Important: Look at your browser's address bar (right side usually). You will see an icon that looks like a Router or Signal Bar. Click it and Allow the connection to localhost.
  5. Get your connection URL from Ubuntu:
sudo docker logs --since=3m colab_local

Copy the URL from the logs: Look for the line starting with http://127.0.0.1:9000...

Example: http://127.0.0.1:9000/?token=d44d0b0f34174fd561623ca9058a3089df5230c5bbd5b7c2

Paste this into the Colab "Backend URL" box and click Connect.


Phase 6: Setting up ComfyUI (The Notebook)

Use the cells below inside your Google Colab Notebook or use one provided Open In Colab.

Cell 1: Environment Setup

Run this cell first. It handles the cloning of the repository and installation of requirements.

#@title Environment Setup

OPTIONS = {}

USE_GOOGLE_DRIVE = False  #@param {type:"boolean"}
UPDATE_COMFY_UI = True  #@param {type:"boolean"}
WORKSPACE = 'ComfyUI'
OPTIONS['USE_GOOGLE_DRIVE'] = USE_GOOGLE_DRIVE
OPTIONS['UPDATE_COMFY_UI'] = UPDATE_COMFY_UI

if OPTIONS['USE_GOOGLE_DRIVE']:
    !echo "Mounting Google Drive..."
    %cd /

    from google.colab import drive
    drive.mount('/content/drive')

    WORKSPACE = "/content/drive/MyDrive/ComfyUI"
    %cd /content/drive/MyDrive

![ ! -d $WORKSPACE ] && echo -= Initial setup ComfyUI =- && git clone https://github.com/comfyanonymous/ComfyUI
%cd $WORKSPACE

if OPTIONS['UPDATE_COMFY_UI']:
  !echo -= Updating ComfyUI =-
  !git pull

!echo -= Install dependencies =-
!pip install xformers!=0.0.18 -r requirements.txt --extra-index-url https://download.pytorch.org/whl/cu121 --extra-index-url https://download.pytorch.org/whl/cu118 --extra-index-url https://download.pytorch.org/whl/cu117

Cell 2: Model Downloads

Run this cell.

try:
    USE_GOOGLE_DRIVE
except NameError:
    %cd /content/ComfyUI
else:
    if USE_GOOGLE_DRIVE == True:
      %cd /content/$WORKSPACE
    else:
      %cd /content/ComfyUI

Then uncomment the models you want to use and run the cell.

# ==============================================================================
# 1. CHECKPOINTS (BASE MODELS)
# ==============================================================================

# --- SDXL (Standard) ---
# Reference: https://comfyanonymous.github.io/ComfyUI_examples/sdxl/
# !wget -c https://huggingface.co/RunDiffusion/Juggernaut-XL-v8/resolve/main/juggernautXL_v8Rundiffusion.safetensors -P ./models/checkpoints/
# !wget -c https://huggingface.co/stabilityai/stable-diffusion-xl-base-1.0/resolve/main/sd_xl_base_1.0.safetensors -P ./models/checkpoints/

# --- SD 1.5 (Standard & Anime) ---
# !wget -c https://huggingface.co/Comfy-Org/stable-diffusion-v1-5-archive/resolve/main/v1-5-pruned-emaonly-fp16.safetensors -P ./models/checkpoints/
# !wget -c https://huggingface.co/Linaqruf/anything-v3.0/resolve/main/anything-v3-fp16-pruned.safetensors -P ./models/checkpoints/

# ==============================================================================
# 2. FLUX MODELS (Next Gen)
# ==============================================================================

# !wget -c https://huggingface.co/city96/FLUX.1-dev-gguf/resolve/main/flux1-dev-Q4_0.gguf -P ./models/diffusion_models/FLUX1/
# !wget -c https://huggingface.co/comfyanonymous/flux_text_encoders/resolve/main/clip_l.safetensors -P ./models/text_encoders/FLUX1/

# ==============================================================================
# 3. SUPPORT MODELS
# ==============================================================================

# --- Upscalers (ESRGAN) ---
# !wget -c https://github.com/xinntao/Real-ESRGAN/releases/download/v0.1.0/RealESRGAN_x4plus.pth -P ./models/upscale_models/
# !wget -c https://huggingface.co/sberbank-ai/Real-ESRGAN/resolve/main/RealESRGAN_x4.pth -P ./models/upscale_models/

# --- ControlNet Preprocessors ---
# !cd custom_nodes && git clone https://github.com/Fannovel16/comfy_controlnet_preprocessors; cd comfy_controlnet_preprocessors && python install.py

Cell 3: Run ComfyUI

Run this final cell to start the server.

# Go to the correct folder after instalation
try:
    USE_GOOGLE_DRIVE
except NameError:
    %cd /content/ComfyUI
else:
    if USE_GOOGLE_DRIVE == True:
      %cd /content/$WORKSPACE
    else:
      %cd /content/ComfyUI

!python main.py --listen 0.0.0.0
# If you are running on the same device you are accessing you can use localhost instead of 0.0.0.0 to prevent browser warnings, so access the link bellow
# http://localhost:8188/

to stop running see bellow


Daily Routine (Cheat Sheet)

1. Start WSL

Open Command Prompt (CMD).

wsl

2. Start the Container

In the Ubuntu terminal:

sudo docker start colab_local

3. Get the Colab Connection URL

Run this to see the logs and copy the token URL (port 9000) for Google Colab.

sudo docker logs --since=3m colab_local

(Copy the http://127.0.0.1:9000/?token=... link and paste it into Colab)

4. Enter the Container (Optional)

Only do this if you want to run ComfyUI manually via terminal instead of using the Colab Notebook cells.

1. Access the container shell:

sudo docker exec -it colab_local /bin/bash

2. Navigate and start ComfyUI:

cd /content/ComfyUI
python main.py --listen 0.0.0.0

5. Stop Everything

If you are running ComfyUI in the terminal (Step 4):

  1. Press Ctrl + C to stop the ComfyUI.
  2. Exit the container shell:
    exit

To shut down docker and wsl:

  1. Stop the container:
    sudo docker stop colab_local
  2. Exit Ubuntu:
    exit
  3. Shutdown WSL:
    wsl --shutdown

🗑️ How to Completely Uninstall WSL

Use this if you want to completely wipe your Linux environment and start over.

Phase 1: Remove Linux Distribution

  1. Open Command Prompt (Admin).
  2. Check installed distros:
    wsl --list --verbose
  3. Unregister (Delete) the distro:
    wsl --unregister Ubuntu
  4. Verify removal:
    wsl --list --verbose

Phase 2: Uninstall Applications

  1. Go to Windows Settings > Apps > Installed Apps.
  2. Search for Ubuntu and click Uninstall.
  3. (Optional) Uninstall Docker Desktop if you installed the Windows version.

Phase 3: Deep File Cleanup

  1. Press Win + R, type %LocalAppData%\Packages, and delete folders starting with CanonicalGroupLimited.Ubuntu.
  2. Press Win + R, type %LocalAppData%\Temp, and delete the wsl-crashes folder.

Phase 4: Disable Windows Features (Optional) Only do this if you never want to use WSL again.

  1. Open Turn Windows features on or off.

  2. Uncheck Windows Subsystem for Linux and Virtual Machine Platform.

  3. Restart your PC.

About

Easily run ComfyUI on Windows using WSL, Docker and Colab

Resources

License

Stars

Watchers

Forks

Releases

No releases published

Packages

 
 
 

Contributors