Difference between revisions of "ComfyUI: Instalasi via docker compose"

From OnnoWiki
Jump to navigation Jump to search
(Created page with "## Menambahkan ComfyUI ke Docker Compose yang sudah ada Cara yang relatif aman adalah **membangun image ComfyUI sendiri dari repositori resmi**, bukan memakai image komunitas...")
 
 
Line 1: Line 1:
## Menambahkan ComfyUI ke Docker Compose yang sudah ada
+
Berikut rangkuman final yang sesuai dengan instalasi yang baru dilakukan.
  
Cara yang relatif aman adalah **membangun image ComfyUI sendiri dari repositori resmi**, bukan memakai image komunitas yang isinya tidak selalu jelas. Instalasi resmi ComfyUI menggunakan repositori `Comfy-Org/ComfyUI`, memasang PyTorch dan `requirements.txt`, lalu menjalankan `main.py`. ComfyUI-Manager sekarang diaktifkan melalui `manager_requirements.txt` dan parameter `--enable-manager`. ([GitHub][1])
+
# Instalasi ComfyUI GPU dengan Docker Compose di Ubuntu 24.04
  
Struktur akhirnya:
+
Panduan ini mendokumentasikan instalasi ComfyUI pada server Ubuntu 24.04 dengan alamat IP `192.168.0.230`. ComfyUI ditambahkan ke dalam Docker Compose yang sebelumnya sudah menjalankan Ollama, Open-WebUI, n8n, dan WAHA.
 +
 
 +
Server menggunakan GPU NVIDIA GeForce RTX 4060 Laptop GPU dengan VRAM sekitar 8 GB.
  
```text
+
---
local-ai/
 
├── compose.yaml
 
└── comfyui/
 
    ├── Dockerfile
 
    ├── .dockerignore
 
    └── data/
 
        ├── models/
 
        ├── input/
 
        ├── output/
 
        ├── custom_nodes/
 
        ├── user/
 
        └── cache/
 
```
 
  
### 1. Pastikan GPU NVIDIA dapat digunakan Docker
+
## 1. Lokasi instalasi
  
Periksa driver:
+
Seluruh stack berada di:
  
 
```bash
 
```bash
nvidia-smi
+
/opt/ai-stack
 
```
 
```
  
Periksa NVIDIA Container Toolkit:
+
File utama Docker Compose:
  
 
```bash
 
```bash
dpkg -l | grep nvidia-container-toolkit
+
/opt/ai-stack/compose.yaml
 
```
 
```
  
Jika belum terpasang:
+
Direktori ComfyUI:
  
 
```bash
 
```bash
curl -fsSL https://nvidia.github.io/libnvidia-container/gpgkey \
+
/opt/ai-stack/comfyui
  | sudo gpg --dearmor \
 
  -o /usr/share/keyrings/nvidia-container-toolkit-keyring.gpg
 
 
```
 
```
  
```bash
+
---
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
 
```
 
  
```bash
+
## 2. Memastikan GPU NVIDIA tersedia
sudo apt update
 
sudo apt install -y nvidia-container-toolkit
 
```
 
  
Konfigurasikan runtime NVIDIA:
+
Periksa GPU pada host:
  
 
```bash
 
```bash
sudo nvidia-ctk runtime configure --runtime=docker
+
nvidia-smi
sudo systemctl restart docker
 
 
```
 
```
  
Itu adalah prosedur resmi NVIDIA untuk Debian dan Ubuntu. ([NVIDIA Docs][2])
+
Kemudian periksa apakah Docker dapat mengakses GPU:
 
 
Tes akses GPU dari container:
 
  
 
```bash
 
```bash
Line 70: Line 47:
 
```
 
```
  
Walaupun host memakai Ubuntu 24.04, container boleh menggunakan basis Ubuntu 22.04.
+
Pengujian berhasil apabila container menampilkan GPU NVIDIA, driver, CUDA, dan kapasitas VRAM.
 +
 
 +
Pada instalasi ini, Docker berhasil mendeteksi:
 +
 
 +
```text
 +
NVIDIA GeForce RTX 4060 Laptop GPU
 +
VRAM sekitar 8188 MiB
 +
NVIDIA Driver 595.71.05
 +
```
 +
 
 +
Artinya NVIDIA Container Toolkit dan integrasi GPU Docker sudah berjalan dengan benar.
  
 
---
 
---
  
## 2. Buat direktori ComfyUI
+
## 3. Membuat direktori ComfyUI
  
Masuk ke direktori tempat `compose.yaml` berada:
+
Masuk ke direktori stack:
  
 
```bash
 
```bash
cd ~/Apps/LocalAI
+
cd /opt/ai-stack
 
```
 
```
  
Sesuaikan apabila lokasi compose berbeda.
+
Buat direktori utama dan direktori data ComfyUI:
 
 
Buat struktur folder:
 
  
 
```bash
 
```bash
mkdir -p comfyui/data/{input,output,custom_nodes,user,cache}
+
mkdir -p comfyui/data/{models,input,output,custom_nodes,user,cache}
 
```
 
```
 +
 +
Buat subdirektori model:
  
 
```bash
 
```bash
Line 94: Line 81:
 
```
 
```
  
Periksa:
+
Struktur akhirnya:
  
```bash
+
```text
find comfyui -maxdepth 3 -type d
+
/opt/ai-stack/
 +
├── compose.yaml
 +
└── comfyui/
 +
    ├── Dockerfile
 +
    ├── .dockerignore
 +
    └── data/
 +
        ├── models/
 +
        │  ├── checkpoints/
 +
        │  ├── vae/
 +
        │  ├── loras/
 +
        │  ├── controlnet/
 +
        │  ├── clip/
 +
        │  ├── clip_vision/
 +
        │  ├── diffusion_models/
 +
        │  ├── text_encoders/
 +
        │  ├── unet/
 +
        │  ├── upscale_models/
 +
        │  └── embeddings/
 +
        ├── input/
 +
        ├── output/
 +
        ├── custom_nodes/
 +
        ├── user/
 +
        └── cache/
 
```
 
```
  
 
---
 
---
  
## 3. Buat Dockerfile ComfyUI
+
## 4. Membuat Dockerfile ComfyUI
  
 
Buat file:
 
Buat file:
  
 
```bash
 
```bash
nano comfyui/Dockerfile
+
cat > /opt/ai-stack/comfyui/Dockerfile <<'EOF'
```
 
 
 
Isi:
 
 
 
```dockerfile
 
 
FROM python:3.12-slim-bookworm
 
FROM python:3.12-slim-bookworm
  
ENV DEBIAN_FRONTEND=noninteractive \
+
ENV DEBIAN_FRONTEND=noninteractive
    PYTHONUNBUFFERED=1 \
+
ENV PYTHONUNBUFFERED=1
    PIP_NO_CACHE_DIR=1
+
ENV PIP_NO_CACHE_DIR=1
  
# Paket sistem yang diperlukan ComfyUI dan berbagai custom node.
 
 
RUN apt-get update && apt-get install -y --no-install-recommends \
 
RUN apt-get update && apt-get install -y --no-install-recommends \
 
     git \
 
     git \
Line 133: Line 136:
 
WORKDIR /opt
 
WORKDIR /opt
  
# Mengambil ComfyUI dari repositori resmi.
+
RUN git clone --depth 1 \
RUN git clone --depth 1 https://github.com/Comfy-Org/ComfyUI.git
+
    https://github.com/Comfy-Org/ComfyUI.git \
 +
    /opt/ComfyUI
  
 
WORKDIR /opt/ComfyUI
 
WORKDIR /opt/ComfyUI
  
# Memasang PyTorch dengan dukungan NVIDIA CUDA 12.8.
+
RUN python -m pip install --upgrade pip setuptools wheel
RUN python -m pip install --upgrade pip setuptools wheel \
+
 
    && python -m pip install \
+
RUN python -m pip install \
      torch torchvision torchaudio \
+
    torch==2.11.0 \
      --index-url https://download.pytorch.org/whl/cu128 \
+
    torchvision==0.26.0 \
    && python -m pip install -r requirements.txt \
+
    torchaudio==2.11.0 \
 +
    --index-url https://download.pytorch.org/whl/cu128
 +
 
 +
RUN python -m pip install -r requirements.txt \
 
     && python -m pip install -r manager_requirements.txt
 
     && python -m pip install -r manager_requirements.txt
  
Line 153: Line 160:
 
     "--enable-manager", \
 
     "--enable-manager", \
 
     "--preview-method", "auto"]
 
     "--preview-method", "auto"]
 +
EOF
 
```
 
```
  
CUDA 12.8 dipilih karena cocok untuk keluarga GPU NVIDIA modern seperti Turing, Ampere, dan Blackwell, termasuk RTX 20, RTX 30, RTX 40, dan RTX 50. PyTorch masih menyediakan wheel CUDA 12.8 secara terpisah. ([GitHub][3])
+
Periksa bahwa file sudah dibuat:
 +
 
 +
```bash
 +
ls -lah /opt/ai-stack/comfyui/Dockerfile
 +
```
 +
 
 +
Hasil instalasi ini menunjukkan:
 +
 
 +
```text
 +
-rw-r--r-- 1 root root 1001 Jul 21 10:58 comfyui/Dockerfile
 +
```
  
 
---
 
---
  
## 4. Buat `.dockerignore`
+
## 5. Membuat `.dockerignore`
  
Ini penting agar file model yang ukurannya puluhan gigabyte tidak ikut dikirim sebagai Docker build context.
+
File ini mencegah direktori model dan hasil gambar ikut dimasukkan ke Docker build context.
  
 
```bash
 
```bash
nano comfyui/.dockerignore
+
cat > /opt/ai-stack/comfyui/.dockerignore <<'EOF'
```
 
 
 
Isi:
 
 
 
```text
 
 
data/
 
data/
 +
.git/
 
__pycache__/
 
__pycache__/
 
*.pyc
 
*.pyc
 
*.pyo
 
*.pyo
.git/
+
EOF
 
```
 
```
  
 
---
 
---
  
## 5. Tambahkan service ComfyUI ke `compose.yaml`
+
## 6. Menambahkan ComfyUI ke Docker Compose
 +
 
 +
Tambahkan service berikut ke dalam `/opt/ai-stack/compose.yaml`.
  
Tambahkan bagian berikut **setelah service `waha` tetapi sebelum bagian paling bawah `volumes:`**:
+
Letakkan bagian ini setelah service WAHA dan sebelum bagian global `volumes:`.
  
 
```yaml
 
```yaml
 
   ################################
 
   ################################
   # 5. COMFYUI (Image Generation)
+
   # 5. COMFYUI (GPU)
 
   ################################
 
   ################################
 
   comfyui:
 
   comfyui:
Line 191: Line 207:
 
       context: ./comfyui
 
       context: ./comfyui
 
       dockerfile: Dockerfile
 
       dockerfile: Dockerfile
 +
 
     image: local/comfyui:cu128
 
     image: local/comfyui:cu128
 
     container_name: comfyui
 
     container_name: comfyui
Line 196: Line 213:
  
 
     ports:
 
     ports:
       - "192.168.0.230:8188:8188"
+
       - "8188:8188"
  
 
     environment:
 
     environment:
Line 219: Line 236:
 
             - driver: nvidia
 
             - driver: nvidia
 
               count: all
 
               count: all
               capabilities: ["gpu"]
+
               capabilities:
 +
                - gpu
 
```
 
```
  
Bagian akhir compose tetap seperti sebelumnya:
+
Bagian volume utama tetap:
  
 
```yaml
 
```yaml
Line 231: Line 249:
 
```
 
```
  
Tidak perlu menambahkan `comfyui_data` karena ComfyUI menggunakan bind mount ke direktori `./comfyui/data`.
+
ComfyUI tidak membutuhkan named volume tambahan karena semua datanya menggunakan bind mount di:
 +
 
 +
```text
 +
/opt/ai-stack/comfyui/data
 +
```
 +
 
 +
---
 +
 
 +
## 7. Memvalidasi Docker Compose
 +
 
 +
Masuk ke direktori stack:
 +
 
 +
```bash
 +
cd /opt/ai-stack
 +
```
 +
 
 +
Validasi konfigurasi:
 +
 
 +
```bash
 +
docker compose config
 +
```
 +
 
 +
Pastikan Compose mendeteksi seluruh service:
  
Docker Compose memang mendukung reservasi GPU melalui `deploy.resources.reservations.devices`, dan `capabilities: ["gpu"]` wajib dicantumkan. ([Docker Documentation][4])
+
```bash
 +
docker compose config --services
 +
```
  
### Tentang pengaturan port
+
Hasilnya harus mencakup:
  
Baris ini:
+
```text
 +
ollama
 +
open-webui
 +
n8n
 +
waha
 +
comfyui
 +
```
 +
 
 +
Pada instalasi ini, konfigurasi ComfyUI terbaca sebagai:
 +
 
 +
```text
 +
build context: /opt/ai-stack/comfyui
 +
dockerfile: Dockerfile
 +
image: local/comfyui:cu128
 +
port: 8188
 +
GPU driver: nvidia
 +
GPU count: all
 +
```
 +
 
 +
---
 +
 
 +
## 8. Kesalahan `docker compose pull`
 +
 
 +
Ketika menjalankan:
 +
 
 +
```bash
 +
docker compose pull
 +
```
 +
 
 +
muncul pesan:
 +
 
 +
```text
 +
pull access denied for local/comfyui
 +
repository does not exist or may require docker login
 +
```
 +
 
 +
Hal ini terjadi karena:
  
 
```yaml
 
```yaml
ports:
+
image: local/comfyui:cu128
  - "192.168.0.230:8188:8188"
 
 
```
 
```
  
berarti ComfyUI hanya mendengarkan melalui alamat LAN server `192.168.0.230`.
+
merupakan image lokal yang harus dibangun dari Dockerfile, bukan diunduh dari Docker Hub.
 +
 
 +
Tidak perlu melakukan `docker login`.
  
Apabila alamat server berbeda, ubah IP tersebut. Untuk membuka melalui seluruh interface, gunakan:
+
Untuk service ComfyUI, gunakan:
  
```yaml
+
```bash
ports:
+
docker compose build comfyui
  - "8188:8188"
 
 
```
 
```
  
Namun ComfyUI sebaiknya tidak langsung dibuka ke internet, terutama ketika Manager aktif karena Manager dapat memasang dan menjalankan kode dari custom node.
+
Untuk memperbarui image service lain tanpa mencoba menarik image ComfyUI:
 +
 
 +
```bash
 +
docker compose pull --ignore-buildable
 +
```
  
 
---
 
---
  
## 6. Validasi YAML
+
## 9. Membangun image ComfyUI
  
 
Jalankan:
 
Jalankan:
  
 
```bash
 
```bash
docker compose config
+
cd /opt/ai-stack
 +
docker compose build comfyui
 
```
 
```
  
Jika tidak ada pesan kesalahan, build hanya service ComfyUI:
+
Docker akan melakukan beberapa hal:
 +
 
 +
* Mengunduh base image Python 3.12.
 +
* Menginstal Git, FFmpeg, library OpenGL, dan compiler.
 +
* Mengambil source code ComfyUI.
 +
* Menginstal PyTorch dengan CUDA 12.8.
 +
* Menginstal seluruh requirement ComfyUI.
 +
* Menginstal ComfyUI-Manager.
 +
* Memberikan nama image `local/comfyui:cu128`.
 +
 
 +
Periksa image setelah build:
  
 
```bash
 
```bash
docker compose build comfyui
+
docker image ls local/comfyui
 
```
 
```
  
Kemudian jalankan:
+
---
 +
 
 +
## 10. Menjalankan ComfyUI
 +
 
 +
Jalankan hanya service ComfyUI:
  
 
```bash
 
```bash
docker compose up -d comfyui
+
docker compose up -d --no-deps comfyui
 
```
 
```
  
Keterangan:
+
Opsi `--no-deps` mencegah Docker Compose menjalankan ulang atau mengubah service lain.
  
* `up` membuat dan menjalankan container.
+
Periksa status:
* `-d` menjalankan container di belakang layar.
 
* `comfyui` berarti hanya service ComfyUI yang dijalankan.
 
  
Periksa status:
+
```bash
 +
docker compose ps comfyui
 +
```
 +
 
 +
Periksa log:
  
 
```bash
 
```bash
docker compose ps
+
docker compose logs -f --tail=100 comfyui
 
```
 
```
  
Seharusnya terdapat:
+
Instalasi berhasil ketika muncul:
  
 
```text
 
```text
comfyui    running    192.168.0.230:8188->8188/tcp
+
[INFO] Starting server
 +
 
 +
[INFO] To see the GUI go to: http://0.0.0.0:8188
 +
```
 +
 
 +
Pada instalasi ini ComfyUI berhasil menjalankan:
 +
 
 +
```text
 +
ComfyUI version: 0.28.0
 +
comfyui-frontend-package version: 1.45.21
 +
ComfyUI-Manager
 
```
 
```
  
 
---
 
---
  
## 7. Periksa log ComfyUI
+
## 11. Peringatan yang aman diabaikan
  
```bash
+
Log menampilkan:
docker compose logs -f --tail=100 comfyui
+
 
 +
```text
 +
The matrix sharing feature has been disabled because the matrix-nio dependency is not installed.
 +
```
 +
 
 +
Ini bukan error. Fitur berbagi melalui Matrix tidak diperlukan untuk penggunaan normal ComfyUI.
 +
 
 +
Log juga menampilkan:
 +
 
 +
```text
 +
No OpenGL_accelerate module loaded
 
```
 
```
  
Cari informasi seperti:
+
Ini juga bukan error fatal. ComfyUI tetap dapat berjalan menggunakan CUDA dan antarmuka web.
 +
 
 +
Tidak perlu memasang kedua modul tersebut apabila ComfyUI sudah berjalan normal.
 +
 
 +
---
 +
 
 +
## 12. Mengakses ComfyUI
 +
 
 +
Buka browser dari komputer yang berada dalam jaringan yang sama:
  
 
```text
 
```text
Device: cuda:0
+
http://192.168.0.230:8188
Using pytorch attention
 
Starting server
 
To see the GUI go to: http://0.0.0.0:8188
 
 
```
 
```
  
Tekan `Ctrl+C` untuk keluar dari tampilan log. Container tetap berjalan.
+
Port `8188` diarahkan dari host ke container:
 +
 
 +
```yaml
 +
ports:
 +
  - "8188:8188"
 +
```
  
 
---
 
---
  
## 8. Verifikasi PyTorch dan GPU
+
## 13. Memastikan ComfyUI menggunakan GPU
  
 
Jalankan:
 
Jalankan:
  
 
```bash
 
```bash
docker exec comfyui python -c \
+
docker exec comfyui python -c '
'import torch; print("CUDA tersedia:", torch.cuda.is_available()); print("PyTorch:", torch.__version__); print("CUDA:", torch.version.cuda); print("GPU:", torch.cuda.get_device_name(0) if torch.cuda.is_available() else "Tidak ada")'
+
import torch
 +
 
 +
print("PyTorch      :", torch.__version__)
 +
print("CUDA runtime  :", torch.version.cuda)
 +
print("CUDA tersedia :", torch.cuda.is_available())
 +
 
 +
if torch.cuda.is_available():
 +
    print("GPU           :", torch.cuda.get_device_name(0))
 +
    print(
 +
        "VRAM          :",
 +
        round(torch.cuda.get_device_properties(0).total_memory / 1024**3, 2),
 +
        "GB"
 +
    )
 +
'
 
```
 
```
  
Line 328: Line 470:
  
 
```text
 
```text
CUDA tersedia: True
+
CUDA tersedia : True
PyTorch: 2.x.x
+
GPU           : NVIDIA GeForce RTX 4060 Laptop GPU
CUDA: 12.8
+
VRAM          : sekitar 8 GB
GPU: NVIDIA GeForce RTX ...
 
 
```
 
```
  
 
---
 
---
  
## 9. Buka ComfyUI
+
## 14. Menyalin model DreamShaper ke server
  
Dari komputer dalam jaringan yang sama:
+
Model berada pada laptop `i3` di:
  
 
```text
 
```text
http://192.168.0.230:8188
+
/home/onno/Downloads/LIBRARY/DreamShaper_8_pruned.safetensors
 
```
 
```
  
ComfyUI tidak menyertakan checkpoint model secara otomatis. Tempatkan file model `*.safetensors` di:
+
Tujuan model di server:
  
 
```text
 
```text
comfyui/data/models/checkpoints/
+
/opt/ai-stack/comfyui/data/models/checkpoints/
 
```
 
```
  
VAE ditempatkan di:
+
Dari laptop `i3`, jalankan:
 +
 
 +
```bash
 +
cd ~/Downloads/LIBRARY
 +
```
 +
 
 +
Kemudian salin menggunakan SCP:
 +
 
 +
```bash
 +
scp DreamShaper_8_pruned.safetensors \
 +
  onno@192.168.0.230:/opt/ai-stack/comfyui/data/models/checkpoints/
 +
```
 +
 
 +
Masukkan password user `onno` pada server.
 +
 
 +
Periksa file dari server:
 +
 
 +
```bash
 +
ssh onno@192.168.0.230
 +
```
 +
 
 +
```bash
 +
ls -lh /opt/ai-stack/comfyui/data/models/checkpoints/
 +
```
 +
 
 +
File yang harus terlihat:
  
 
```text
 
```text
comfyui/data/models/vae/
+
DreamShaper_8_pruned.safetensors
 +
```
 +
 
 +
---
 +
 
 +
## 15. Jika terjadi `Permission denied` saat SCP
 +
 
 +
Salin dahulu ke home user:
 +
 
 +
```bash
 +
scp DreamShaper_8_pruned.safetensors \
 +
  onno@192.168.0.230:/home/onno/
 +
```
 +
 
 +
Masuk ke server:
 +
 
 +
```bash
 +
ssh onno@192.168.0.230
 +
```
 +
 
 +
Pindahkan menggunakan `sudo`:
 +
 
 +
```bash
 +
sudo mv ~/DreamShaper_8_pruned.safetensors \
 +
  /opt/ai-stack/comfyui/data/models/checkpoints/
 
```
 
```
  
LoRA ditempatkan di:
+
Atur kepemilikan:
  
```text
+
```bash
comfyui/data/models/loras/
+
sudo chown onno:onno \
 +
  /opt/ai-stack/comfyui/data/models/checkpoints/DreamShaper_8_pruned.safetensors
 +
```
 +
 
 +
---
 +
 
 +
## 16. Mengatur kepemilikan direktori ComfyUI
 +
 
 +
Karena beberapa file dibuat sebagai `root`, ubah kepemilikannya agar user `onno` dapat mengelola model, input, dan output:
 +
 
 +
```bash
 +
sudo chown -R onno:onno /opt/ai-stack/comfyui
 +
```
 +
 
 +
Periksa:
 +
 
 +
```bash
 +
ls -ld /opt/ai-stack/comfyui
 +
ls -ld /opt/ai-stack/comfyui/data/models/checkpoints
 
```
 
```
  
Lokasi checkpoint dan VAE tersebut sesuai struktur model resmi ComfyUI. ([GitHub][1])
+
---
 +
 
 +
## 17. Memuat model yang baru disalin
  
Setelah memasukkan model, restart:
+
Setelah model selesai disalin, restart ComfyUI:
  
 
```bash
 
```bash
 +
cd /opt/ai-stack
 
docker compose restart comfyui
 
docker compose restart comfyui
 
```
 
```
 +
 +
Pantau log:
 +
 +
```bash
 +
docker compose logs -f --tail=100 comfyui
 +
```
 +
 +
Kemudian muat ulang halaman browser:
 +
 +
```text
 +
http://192.168.0.230:8188
 +
```
 +
 +
Pada node `Load Checkpoint`, pilih:
 +
 +
```text
 +
DreamShaper_8_pruned.safetensors
 +
```
 +
 +
DreamShaper 8 merupakan checkpoint berbasis Stable Diffusion 1.5, sehingga relatif sesuai untuk GPU dengan VRAM 8 GB.
  
 
---
 
---
  
## 10. Perintah operasional
+
## 18. Perintah operasional sehari-hari
  
Menghentikan ComfyUI saja:
+
Menjalankan ComfyUI:
  
 
```bash
 
```bash
docker compose stop comfyui
+
cd /opt/ai-stack
 +
docker compose start comfyui
 
```
 
```
  
Menjalankannya kembali:
+
Menghentikan ComfyUI:
  
 
```bash
 
```bash
docker compose start comfyui
+
docker compose stop comfyui
 
```
 
```
  
Line 392: Line 624:
 
```
 
```
  
Menghapus container tanpa menghapus model dan hasil gambar:
+
Melihat status:
  
 
```bash
 
```bash
docker compose rm -sf comfyui
+
docker compose ps comfyui
 
```
 
```
  
Membangun ulang ComfyUI versi terbaru:
+
Melihat log:
 +
 
 +
```bash
 +
docker compose logs -f --tail=100 comfyui
 +
```
 +
 
 +
Membangun ulang setelah Dockerfile berubah:
 +
 
 +
```bash
 +
docker compose build comfyui
 +
docker compose up -d --no-deps comfyui
 +
```
 +
 
 +
Membangun ulang tanpa menggunakan build cache:
  
 
```bash
 
```bash
 
docker compose build --no-cache comfyui
 
docker compose build --no-cache comfyui
docker compose up -d comfyui
+
docker compose up -d --no-deps comfyui
 
```
 
```
  
`--no-cache` memaksa Docker mengambil ulang kode dan memasang ulang dependency, bukan menggunakan layer build lama.
+
---
  
---
+
## 19. Penggunaan bersama Ollama
  
## Jika VRAM tidak cukup
+
Ollama dan ComfyUI menggunakan GPU yang sama.
  
Ollama dan ComfyUI memakai GPU NVIDIA yang sama. Ketika model Ollama masih berada di VRAM, ComfyUI dapat mengalami:
+
RTX 4060 memiliki VRAM sekitar 8 GB. Jika model Ollama masih berada dalam VRAM, ComfyUI dapat kehabisan memori dan menampilkan:
  
 
```text
 
```text
Line 417: Line 662:
 
```
 
```
  
Untuk pengujian, hentikan Ollama sementara:
+
Sebelum menghasilkan gambar besar, Ollama dapat dihentikan sementara:
  
 
```bash
 
```bash
 +
cd /opt/ai-stack
 
docker compose stop ollama
 
docker compose stop ollama
 
```
 
```
  
Jalankan ComfyUI:
+
Restart ComfyUI:
  
 
```bash
 
```bash
Line 429: Line 675:
 
```
 
```
  
Setelah selesai membuat gambar:
+
Setelah selesai menggunakan ComfyUI, jalankan kembali Ollama:
  
 
```bash
 
```bash
Line 435: Line 681:
 
```
 
```
  
Terakhir, sebaiknya pindahkan `WHATSAPP_API_KEY`, password dashboard WAHA, dan password Swagger dari YAML ke file `.env`, serta ganti nilai password yang saat ini masih sederhana sebelum server dapat diakses pengguna lain.
+
---
 +
 
 +
## 20. Lokasi file penting
 +
 
 +
Dockerfile:
 +
 
 +
```text
 +
/opt/ai-stack/comfyui/Dockerfile
 +
```
 +
 
 +
Docker Compose:
 +
 
 +
```text
 +
/opt/ai-stack/compose.yaml
 +
```
 +
 
 +
Checkpoint:
 +
 
 +
```text
 +
/opt/ai-stack/comfyui/data/models/checkpoints/
 +
```
 +
 
 +
LoRA:
 +
 
 +
```text
 +
/opt/ai-stack/comfyui/data/models/loras/
 +
```
 +
 
 +
VAE:
 +
 
 +
```text
 +
/opt/ai-stack/comfyui/data/models/vae/
 +
```
 +
 
 +
Input gambar:
 +
 
 +
```text
 +
/opt/ai-stack/comfyui/data/input/
 +
```
 +
 
 +
Hasil gambar:
 +
 
 +
```text
 +
/opt/ai-stack/comfyui/data/output/
 +
```
 +
 
 +
Custom node:
 +
 
 +
```text
 +
/opt/ai-stack/comfyui/data/custom_nodes/
 +
```
 +
 
 +
Cache model:
 +
 
 +
```text
 +
/opt/ai-stack/comfyui/data/cache/
 +
```
 +
 
 +
---
 +
 
 +
## 21. Status akhir instalasi
 +
 
 +
ComfyUI telah berhasil:
 +
 
 +
* Dibangun menggunakan Dockerfile lokal.
 +
* Ditambahkan sebagai service kelima di Docker Compose.
 +
* Mengakses GPU NVIDIA melalui NVIDIA Container Toolkit.
 +
* Menjalankan PyTorch dengan dukungan CUDA.
 +
* Menjalankan ComfyUI-Manager.
 +
* Membuka antarmuka web pada port `8188`.
 +
* Menyimpan model, input, output, dan custom node secara persisten di host.
 +
* Siap menggunakan checkpoint `DreamShaper_8_pruned.safetensors`.
 +
 
 +
Alamat akses akhir:
 +
 
 +
```text
 +
http://192.168.0.230:8188
 +
```
  
[1]: https://github.com/comfy-org/ComfyUI "GitHub - Comfy-Org/ComfyUI: The most powerful and modular diffusion model GUI, api and backend with a graph/nodes interface. · GitHub"
+
Panduan ini dapat langsung disimpan sebagai `/opt/ai-stack/README-ComfyUI.md`.
[2]: https://docs.nvidia.com/datacenter/cloud-native/container-toolkit/1.17.7/install-guide.html "Installing the NVIDIA Container Toolkit — NVIDIA Container Toolkit"
 
[3]: https://github.com/pytorch/pytorch/releases?utm_source=chatgpt.com "Releases · pytorch/pytorch"
 
[4]: https://docs.docker.com/compose/how-tos/gpu-support/ "Run Docker Compose services with GPU access | Docker Docs"
 

Latest revision as of 18:39, 21 July 2026

Berikut rangkuman final yang sesuai dengan instalasi yang baru dilakukan.

  1. Instalasi ComfyUI GPU dengan Docker Compose di Ubuntu 24.04

Panduan ini mendokumentasikan instalasi ComfyUI pada server Ubuntu 24.04 dengan alamat IP `192.168.0.230`. ComfyUI ditambahkan ke dalam Docker Compose yang sebelumnya sudah menjalankan Ollama, Open-WebUI, n8n, dan WAHA.

Server menggunakan GPU NVIDIA GeForce RTX 4060 Laptop GPU dengan VRAM sekitar 8 GB.

---

    1. 1. Lokasi instalasi

Seluruh stack berada di:

```bash /opt/ai-stack ```

File utama Docker Compose:

```bash /opt/ai-stack/compose.yaml ```

Direktori ComfyUI:

```bash /opt/ai-stack/comfyui ```

---

    1. 2. Memastikan GPU NVIDIA tersedia

Periksa GPU pada host:

```bash nvidia-smi ```

Kemudian periksa apakah Docker dapat mengakses GPU:

```bash docker run --rm --gpus all \

 nvidia/cuda:12.9.0-base-ubuntu22.04 \
 nvidia-smi

```

Pengujian berhasil apabila container menampilkan GPU NVIDIA, driver, CUDA, dan kapasitas VRAM.

Pada instalasi ini, Docker berhasil mendeteksi:

```text NVIDIA GeForce RTX 4060 Laptop GPU VRAM sekitar 8188 MiB NVIDIA Driver 595.71.05 ```

Artinya NVIDIA Container Toolkit dan integrasi GPU Docker sudah berjalan dengan benar.

---

    1. 3. Membuat direktori ComfyUI

Masuk ke direktori stack:

```bash cd /opt/ai-stack ```

Buat direktori utama dan direktori data ComfyUI:

```bash mkdir -p comfyui/data/{models,input,output,custom_nodes,user,cache} ```

Buat subdirektori model:

```bash mkdir -p comfyui/data/models/{checkpoints,vae,loras,controlnet,clip,clip_vision,diffusion_models,text_encoders,unet,upscale_models,embeddings} ```

Struktur akhirnya:

```text /opt/ai-stack/ ├── compose.yaml └── comfyui/

   ├── Dockerfile
   ├── .dockerignore
   └── data/
       ├── models/
       │   ├── checkpoints/
       │   ├── vae/
       │   ├── loras/
       │   ├── controlnet/
       │   ├── clip/
       │   ├── clip_vision/
       │   ├── diffusion_models/
       │   ├── text_encoders/
       │   ├── unet/
       │   ├── upscale_models/
       │   └── embeddings/
       ├── input/
       ├── output/
       ├── custom_nodes/
       ├── user/
       └── cache/

```

---

    1. 4. Membuat Dockerfile ComfyUI

Buat file:

```bash cat > /opt/ai-stack/comfyui/Dockerfile <<'EOF' FROM python:3.12-slim-bookworm

ENV DEBIAN_FRONTEND=noninteractive ENV PYTHONUNBUFFERED=1 ENV PIP_NO_CACHE_DIR=1

RUN apt-get update && apt-get install -y --no-install-recommends \

   git \
   ca-certificates \
   curl \
   ffmpeg \
   build-essential \
   libgl1 \
   libglib2.0-0 \
   libgomp1 \
   && rm -rf /var/lib/apt/lists/*

WORKDIR /opt

RUN git clone --depth 1 \

   https://github.com/Comfy-Org/ComfyUI.git \
   /opt/ComfyUI

WORKDIR /opt/ComfyUI

RUN python -m pip install --upgrade pip setuptools wheel

RUN python -m pip install \

   torch==2.11.0 \
   torchvision==0.26.0 \
   torchaudio==2.11.0 \
   --index-url https://download.pytorch.org/whl/cu128

RUN python -m pip install -r requirements.txt \

   && python -m pip install -r manager_requirements.txt

EXPOSE 8188

CMD ["python", "main.py", \

    "--listen", "0.0.0.0", \
    "--port", "8188", \
    "--enable-manager", \
    "--preview-method", "auto"]

EOF ```

Periksa bahwa file sudah dibuat:

```bash ls -lah /opt/ai-stack/comfyui/Dockerfile ```

Hasil instalasi ini menunjukkan:

```text -rw-r--r-- 1 root root 1001 Jul 21 10:58 comfyui/Dockerfile ```

---

    1. 5. Membuat `.dockerignore`

File ini mencegah direktori model dan hasil gambar ikut dimasukkan ke Docker build context.

```bash cat > /opt/ai-stack/comfyui/.dockerignore <<'EOF' data/ .git/ __pycache__/

  • .pyc
  • .pyo

EOF ```

---

    1. 6. Menambahkan ComfyUI ke Docker Compose

Tambahkan service berikut ke dalam `/opt/ai-stack/compose.yaml`.

Letakkan bagian ini setelah service WAHA dan sebelum bagian global `volumes:`.

```yaml

 ################################
 # 5. COMFYUI (GPU)
 ################################
 comfyui:
   build:
     context: ./comfyui
     dockerfile: Dockerfile
   image: local/comfyui:cu128
   container_name: comfyui
   restart: unless-stopped
   ports:
     - "8188:8188"
   environment:
     - TZ=Asia/Jakarta
     - NVIDIA_VISIBLE_DEVICES=all
     - NVIDIA_DRIVER_CAPABILITIES=compute,utility
   volumes:
     - ./comfyui/data/models:/opt/ComfyUI/models
     - ./comfyui/data/input:/opt/ComfyUI/input
     - ./comfyui/data/output:/opt/ComfyUI/output
     - ./comfyui/data/custom_nodes:/opt/ComfyUI/custom_nodes
     - ./comfyui/data/user:/opt/ComfyUI/user
     - ./comfyui/data/cache:/root/.cache
   shm_size: "8gb"
   deploy:
     resources:
       reservations:
         devices:
           - driver: nvidia
             count: all
             capabilities:
               - gpu

```

Bagian volume utama tetap:

```yaml volumes:

 ollama_data:
 openwebui_data:
 n8n_data:

```

ComfyUI tidak membutuhkan named volume tambahan karena semua datanya menggunakan bind mount di:

```text /opt/ai-stack/comfyui/data ```

---

    1. 7. Memvalidasi Docker Compose

Masuk ke direktori stack:

```bash cd /opt/ai-stack ```

Validasi konfigurasi:

```bash docker compose config ```

Pastikan Compose mendeteksi seluruh service:

```bash docker compose config --services ```

Hasilnya harus mencakup:

```text ollama open-webui n8n waha comfyui ```

Pada instalasi ini, konfigurasi ComfyUI terbaca sebagai:

```text build context: /opt/ai-stack/comfyui dockerfile: Dockerfile image: local/comfyui:cu128 port: 8188 GPU driver: nvidia GPU count: all ```

---

    1. 8. Kesalahan `docker compose pull`

Ketika menjalankan:

```bash docker compose pull ```

muncul pesan:

```text pull access denied for local/comfyui repository does not exist or may require docker login ```

Hal ini terjadi karena:

```yaml image: local/comfyui:cu128 ```

merupakan image lokal yang harus dibangun dari Dockerfile, bukan diunduh dari Docker Hub.

Tidak perlu melakukan `docker login`.

Untuk service ComfyUI, gunakan:

```bash docker compose build comfyui ```

Untuk memperbarui image service lain tanpa mencoba menarik image ComfyUI:

```bash docker compose pull --ignore-buildable ```

---

    1. 9. Membangun image ComfyUI

Jalankan:

```bash cd /opt/ai-stack docker compose build comfyui ```

Docker akan melakukan beberapa hal:

  • Mengunduh base image Python 3.12.
  • Menginstal Git, FFmpeg, library OpenGL, dan compiler.
  • Mengambil source code ComfyUI.
  • Menginstal PyTorch dengan CUDA 12.8.
  • Menginstal seluruh requirement ComfyUI.
  • Menginstal ComfyUI-Manager.
  • Memberikan nama image `local/comfyui:cu128`.

Periksa image setelah build:

```bash docker image ls local/comfyui ```

---

    1. 10. Menjalankan ComfyUI

Jalankan hanya service ComfyUI:

```bash docker compose up -d --no-deps comfyui ```

Opsi `--no-deps` mencegah Docker Compose menjalankan ulang atau mengubah service lain.

Periksa status:

```bash docker compose ps comfyui ```

Periksa log:

```bash docker compose logs -f --tail=100 comfyui ```

Instalasi berhasil ketika muncul:

```text [INFO] Starting server

[INFO] To see the GUI go to: http://0.0.0.0:8188 ```

Pada instalasi ini ComfyUI berhasil menjalankan:

```text ComfyUI version: 0.28.0 comfyui-frontend-package version: 1.45.21 ComfyUI-Manager ```

---

    1. 11. Peringatan yang aman diabaikan

Log menampilkan:

```text The matrix sharing feature has been disabled because the matrix-nio dependency is not installed. ```

Ini bukan error. Fitur berbagi melalui Matrix tidak diperlukan untuk penggunaan normal ComfyUI.

Log juga menampilkan:

```text No OpenGL_accelerate module loaded ```

Ini juga bukan error fatal. ComfyUI tetap dapat berjalan menggunakan CUDA dan antarmuka web.

Tidak perlu memasang kedua modul tersebut apabila ComfyUI sudah berjalan normal.

---

    1. 12. Mengakses ComfyUI

Buka browser dari komputer yang berada dalam jaringan yang sama:

```text http://192.168.0.230:8188 ```

Port `8188` diarahkan dari host ke container:

```yaml ports:

 - "8188:8188"

```

---

    1. 13. Memastikan ComfyUI menggunakan GPU

Jalankan:

```bash docker exec comfyui python -c ' import torch

print("PyTorch :", torch.__version__) print("CUDA runtime :", torch.version.cuda) print("CUDA tersedia :", torch.cuda.is_available())

if torch.cuda.is_available():

   print("GPU           :", torch.cuda.get_device_name(0))
   print(
       "VRAM          :",
       round(torch.cuda.get_device_properties(0).total_memory / 1024**3, 2),
       "GB"
   )

' ```

Hasil yang diharapkan:

```text CUDA tersedia : True GPU : NVIDIA GeForce RTX 4060 Laptop GPU VRAM : sekitar 8 GB ```

---

    1. 14. Menyalin model DreamShaper ke server

Model berada pada laptop `i3` di:

```text /home/onno/Downloads/LIBRARY/DreamShaper_8_pruned.safetensors ```

Tujuan model di server:

```text /opt/ai-stack/comfyui/data/models/checkpoints/ ```

Dari laptop `i3`, jalankan:

```bash cd ~/Downloads/LIBRARY ```

Kemudian salin menggunakan SCP:

```bash scp DreamShaper_8_pruned.safetensors \

 onno@192.168.0.230:/opt/ai-stack/comfyui/data/models/checkpoints/

```

Masukkan password user `onno` pada server.

Periksa file dari server:

```bash ssh onno@192.168.0.230 ```

```bash ls -lh /opt/ai-stack/comfyui/data/models/checkpoints/ ```

File yang harus terlihat:

```text DreamShaper_8_pruned.safetensors ```

---

    1. 15. Jika terjadi `Permission denied` saat SCP

Salin dahulu ke home user:

```bash scp DreamShaper_8_pruned.safetensors \

 onno@192.168.0.230:/home/onno/

```

Masuk ke server:

```bash ssh onno@192.168.0.230 ```

Pindahkan menggunakan `sudo`:

```bash sudo mv ~/DreamShaper_8_pruned.safetensors \

 /opt/ai-stack/comfyui/data/models/checkpoints/

```

Atur kepemilikan:

```bash sudo chown onno:onno \

 /opt/ai-stack/comfyui/data/models/checkpoints/DreamShaper_8_pruned.safetensors

```

---

    1. 16. Mengatur kepemilikan direktori ComfyUI

Karena beberapa file dibuat sebagai `root`, ubah kepemilikannya agar user `onno` dapat mengelola model, input, dan output:

```bash sudo chown -R onno:onno /opt/ai-stack/comfyui ```

Periksa:

```bash ls -ld /opt/ai-stack/comfyui ls -ld /opt/ai-stack/comfyui/data/models/checkpoints ```

---

    1. 17. Memuat model yang baru disalin

Setelah model selesai disalin, restart ComfyUI:

```bash cd /opt/ai-stack docker compose restart comfyui ```

Pantau log:

```bash docker compose logs -f --tail=100 comfyui ```

Kemudian muat ulang halaman browser:

```text http://192.168.0.230:8188 ```

Pada node `Load Checkpoint`, pilih:

```text DreamShaper_8_pruned.safetensors ```

DreamShaper 8 merupakan checkpoint berbasis Stable Diffusion 1.5, sehingga relatif sesuai untuk GPU dengan VRAM 8 GB.

---

    1. 18. Perintah operasional sehari-hari

Menjalankan ComfyUI:

```bash cd /opt/ai-stack docker compose start comfyui ```

Menghentikan ComfyUI:

```bash docker compose stop comfyui ```

Restart:

```bash docker compose restart comfyui ```

Melihat status:

```bash docker compose ps comfyui ```

Melihat log:

```bash docker compose logs -f --tail=100 comfyui ```

Membangun ulang setelah Dockerfile berubah:

```bash docker compose build comfyui docker compose up -d --no-deps comfyui ```

Membangun ulang tanpa menggunakan build cache:

```bash docker compose build --no-cache comfyui docker compose up -d --no-deps comfyui ```

---

    1. 19. Penggunaan bersama Ollama

Ollama dan ComfyUI menggunakan GPU yang sama.

RTX 4060 memiliki VRAM sekitar 8 GB. Jika model Ollama masih berada dalam VRAM, ComfyUI dapat kehabisan memori dan menampilkan:

```text CUDA out of memory ```

Sebelum menghasilkan gambar besar, Ollama dapat dihentikan sementara:

```bash cd /opt/ai-stack docker compose stop ollama ```

Restart ComfyUI:

```bash docker compose restart comfyui ```

Setelah selesai menggunakan ComfyUI, jalankan kembali Ollama:

```bash docker compose start ollama ```

---

    1. 20. Lokasi file penting

Dockerfile:

```text /opt/ai-stack/comfyui/Dockerfile ```

Docker Compose:

```text /opt/ai-stack/compose.yaml ```

Checkpoint:

```text /opt/ai-stack/comfyui/data/models/checkpoints/ ```

LoRA:

```text /opt/ai-stack/comfyui/data/models/loras/ ```

VAE:

```text /opt/ai-stack/comfyui/data/models/vae/ ```

Input gambar:

```text /opt/ai-stack/comfyui/data/input/ ```

Hasil gambar:

```text /opt/ai-stack/comfyui/data/output/ ```

Custom node:

```text /opt/ai-stack/comfyui/data/custom_nodes/ ```

Cache model:

```text /opt/ai-stack/comfyui/data/cache/ ```

---

    1. 21. Status akhir instalasi

ComfyUI telah berhasil:

  • Dibangun menggunakan Dockerfile lokal.
  • Ditambahkan sebagai service kelima di Docker Compose.
  • Mengakses GPU NVIDIA melalui NVIDIA Container Toolkit.
  • Menjalankan PyTorch dengan dukungan CUDA.
  • Menjalankan ComfyUI-Manager.
  • Membuka antarmuka web pada port `8188`.
  • Menyimpan model, input, output, dan custom node secara persisten di host.
  • Siap menggunakan checkpoint `DreamShaper_8_pruned.safetensors`.

Alamat akses akhir:

```text http://192.168.0.230:8188 ```

Panduan ini dapat langsung disimpan sebagai `/opt/ai-stack/README-ComfyUI.md`.