### [ComfyUI](https://github.com/comfyanonymous/ComfyUI)

> Handle: `comfyui`<br/>
> URL: [http://localhost:34031](http://localhost:34031)

<div>

[![Website][website-shield]][website-url]
[![Dynamic JSON Badge][discord-shield]][discord-url]
[![Matrix][matrix-shield]][matrix-url]
<br>
[![][github-release-shield]][github-release-link]
[![][github-release-date-shield]][github-release-link]
[![][github-downloads-shield]][github-downloads-link]
[![][github-downloads-latest-shield]][github-downloads-link]

[matrix-shield]: https://img.shields.io/badge/Matrix-000000?style=flat&logo=matrix&logoColor=white
[matrix-url]: https://app.element.io/#/room/%23comfyui_space%3Amatrix.org
[website-shield]: https://img.shields.io/badge/ComfyOrg-4285F4?style=flat
[website-url]: https://www.comfy.org/
<!-- Workaround to display total user from https://github.com/badges/shields/issues/4500#issuecomment-2060079995 -->
[discord-shield]: https://img.shields.io/badge/dynamic/json?url=https%3A%2F%2Fdiscord.com%2Fapi%2Finvites%2Fcomfyorg%3Fwith_counts%3Dtrue&query=%24.approximate_member_count&logo=discord&logoColor=white&label=Discord&color=green&suffix=%20total
[discord-url]: https://www.comfy.org/discord

[github-release-shield]: https://img.shields.io/github/v/release/comfyanonymous/ComfyUI?style=flat&sort=semver
[github-release-link]: https://github.com/comfyanonymous/ComfyUI/releases
[github-release-date-shield]: https://img.shields.io/github/release-date/comfyanonymous/ComfyUI?style=flat
[github-downloads-shield]: https://img.shields.io/github/downloads/comfyanonymous/ComfyUI/total?style=flat
[github-downloads-latest-shield]: https://img.shields.io/github/downloads/comfyanonymous/ComfyUI/latest/total?style=flat&label=downloads%40latest
[github-downloads-link]: https://github.com/comfyanonymous/ComfyUI/releases

![ComfyUI Screenshot](https://github.com/user-attachments/assets/7ccaf2c1-9b72-41ae-9a89-5688c94b7abe)
</div>

This ui will let you design and execute advanced stable diffusion pipelines using a graph/nodes/flowchart based interface.

> [!NOTE]
> The initial download of the models will take upwards of 10 minutes, depending on your internet connection.
> Monitor the logs during the startup to see the progress.

#### Starting

```bash
# [Optional] Pre-pull the comfyui images, ~4GB
# otherwise will be pulled on start
harbor pull comfyui

# Start the service
# Note that this will take a really long time
# for the initial model download
# [Optional] --tail will automatically follow the logs
harbor up comfyui --tail

# See service logs
harbor logs comfyui -n 100

# [Optional] once started, open the UI
# in your default browser
harbor open comfyui
```

- When running with other inference backends - ensure that you have VRAM available for the models. Unlike `ollama`, `comfyui` won't try to offload if there's not enough VRAM. You can check the VRAM usage with [`harbor top`](./3.-Harbor-CLI-Reference.md#harbor-top)
- Harbor's default workflow for the `comfyui` is very basic to get you started, explore the ComfyUI documentation to learn more about the advanced features
- ⚠️ Due to how Harbor's ComfyUI container is structured, after modifying container packages, you must run `harbor comfyui workspace sync` to persist the changes to the local workspace, otherwise they will be lost on the next restart.
- ⚠️ `ai-dock` wasn't updated since November 2024, so you'll likely want to update ComfyUI

To update ComfyUI via the Web interface, you can follow these steps:
![update steps](./harbor-comfyui-update.png)

After update, please sync the workspace to avoid losing changes on restart:

```bash
harbor comfyui workspace sync
```

#### Integrations

`comfyui` (AI-Dock powered ComfyUI node-based interface on port 34031, plus auxiliary portal and Syncthing UIs) is automatically wired as the image-generation backend for Open WebUI. All models, LoRAs, workflows, and outputs are persisted through a host-owned workspace volume. Cross-compose overlays handle GPU passthrough and reverse-proxy exposure.

**Frontends and tools that auto-configure for comfyui**

- `webui` (Open WebUI) — mounts `config.comfyui.json` registering ComfyUI as the `image_generation` engine. It uses the internal service URL `http://comfyui:34031` together with a default Flux.1-schnell workflow and explicit node-id mappings for prompt, unet, width/height, steps, etc. This powers the "Image Generation" feature inside WebUI chats. (Incompatible with ComfyUI auth enabled.)

**Reverse proxy / external access**

- With `traefik` present: `compose.x.traefik.comfyui.yml` adds Traefik labels so the UI is reachable at `https://comfyui.${HARBOR_TRAEFIK_DOMAIN}` (websecure entrypoint, port derived from `HARBOR_COMFYUI_HOST_PORT`).

**Hardware acceleration (GPU / accelerator)**

- NVIDIA passthrough is supplied by `compose.x.comfyui.nvidia.yml` (nvidia driver) or the CDI-generated `compose.x.comfyui.cdi.yml`.
- The container image variant (`latest-cuda`, `latest-rocm`, `latest-cpu`, ...) is selected via the `HARBOR_COMFYUI_VERSION` tag on the ai-dock GHCR image; the ai-dock base detects and activates the accelerator when the corresponding devices are mounted by the overlay.

**Host / volume interactions**

- **Workspace (models, LoRAs, custom nodes, outputs)**: `${HARBOR_COMFYUI_WORKSPACE}` on the host (defaults to `./services/comfyui/workspace`) is bind-mounted at `/workspace` inside the container. The default provisioning script (sourced from `HARBOR_COMFYUI_PROVISIONING`) populates Flux.1-schnell, its text encoders, VAE, and ESRGAN models under the standard `storage/stable_diffusion/models/{ckpt,unet,vae,clip,lora,esrgan,...}` paths on first boot. All user-generated images, workflows, and installed custom nodes also live here.

- **Ownership sidecar**: `comfyui-init` (alpine) runs to successful completion before the main service and chowns the bind mount to `HARBOR_USER_ID:HARBOR_GROUP_ID` (0775). This keeps the directory fully manageable from the host without `sudo`.

- **Packages volume**: `./services/comfyui/packages` (host) ↔ `/opt/comfyui-packages` (container) — persists Python packages installed for custom nodes.

- **Provisioning & workflow**: The entrypoint executes the referenced provisioning script (Harbor's ships a Flux-focused one for WebUI compatibility) and injects `default-workflow.json` to override the initial graph shown in the UI.

- **Workspace sync / persistence**: The ai-dock container works with an internal copy of the workspace; after installing custom nodes or modifying container-side packages you must run `harbor comfyui workspace sync` (or use the built-in Syncthing UI on the third exposed port) to push changes back to the host bind mount. The second port gives access to the AI-Dock management portal.

- The main service declares a `depends_on` on the init sidecar so the workspace is prepared and owned before ComfyUI starts listening.

All wiring happens through the thin overlay files (`compose.x.comfyui.*.yml`, `compose.x.webui.comfyui.yml`, `compose.x.traefik.comfyui.yml`). After any Harbor config change that affects volumes, ports, or GPU, run `harbor config update` (when required) and restart the service(s) involved.

#### Authentication

> [!NOTE]
> Harbor uses [AI Dock](https://github.com/ai-dock/comfyui) to run ComfyUI. By default, it has authentication disabled, but you should re-enable it if exposing the ComfyUI over the network (sadly Open WebUI integration won't work when auth is enabled).

```bash
# Enable web AI Dock auth
harbor comfyui auth true

# Get current login credentials
harbor comfyui user
harbor comfyui password

# Set new login credentials
harbor comfyui user me
harbor comfyui password mypassword

# Underlying config aliases and ENV variables
harbor config get comfyui.user     # HARBOR_COMFYUI_USER
harbor config get comfyui.password # HARBOR_COMFYUI_PASSWORD

# Underlying config aliases and ENV variables
harbor config get comfyui.auth     # HARBOR_COMFYUI_AUTH
```

When enabled, the `comfyui.password` can also be used as a token for ComfyUI API. See [this file](https://github.com/ai-dock/base-image/blob/b8bc35fa2f941339d0895e99d98e4f0f22593957/build/COPY_ROOT_0/opt/caddy/share/base_config#L42) in ai-dock to see all possible auth ways.

#### Usage

Harbor uses AI Dock setup that includes a provisioning script for Flux models compatible with the Open WebUI. You can find provisioning script documentation [here](https://github.com/ai-dock/base-image/wiki/4.0-Running-the-Image#provisioning-script), and list of available scripts in the AI Dock's ComfyUI repo [here](https://github.com/ai-dock/comfyui/tree/main/config/provisioning).

#### Configuration

By default, Harbor will load ComfyUI pre-configured to run FLUX models.

ComfyUI is mainly configured via the UI itself. Harbor will use the `comfyui` folder in the workspace to store the configuration files.

```bash
# Show ComfyUI workspace folder
echo $(harbor home)/services/comfyui
```

> [!IMPORTANT]
> ComfyUI uses `pip` dependencies for managing custom nodes. Those are not automatically synced to the local workspace, so won't automatically persist between Harbor restarts.

```bash
# Sync workspace after updating the nodes
harbor comfyui workspace sync
```

Additional configuration via Harbor CLI:

```bash
# See current version
harbor comfyui version

# Set the version to use
# Accepts package tags from
# AI Dock GHCR: https://github.com/ai-dock/comfyui/pkgs/container/comfyui
harbor comfyui version latest-rocm
```

Following options are available via [`harbor config`](./3.-Harbor-CLI-Reference.md#harbor-config):

```bash
# The port of the ComfyUI's web interface
HARBOR_COMFYUI_HOST_PORT       34031

# web interface for AI Dock UI from ComfyUI container
HARBOR_COMFYUI_PORTAL_HOST_PORT 34032

# Syncthing UI port for workspace sync
HARBOR_COMFYUI_SYNCTHING_HOST_PORT 34033

# Docker image tag to use, can be set to
# "latest-rocm" or "latest-cpu" see:
# https://github.com/ai-dock/comfyui/pkgs/container/comfyui
HARBOR_COMFYUI_VERSION         latest-cuda

# Location of the folder where ComfyUI will store
# models, nodes, and other configuration files
# Has to be either relative to $(harbor home) or an absolute path
HARBOR_COMFYUI_WORKSPACE       ./services/comfyui/workspace

# Enable or disable authentication
# (AI Dock) feature
HARBOR_COMFYUI_AUTH            false

# User and password for the AI Dock
# If the auth is enabled
HARBOR_COMFYUI_USER            harbor
HARBOR_COMFYUI_PASSWORD        sk-comfyui

# Additional arguments for the ComfyUI
HARBOR_COMFYUI_ARGS

# The URL to the provisioning script
# that'll be run to initialise fresh ComfyUI instance
# You can find more provisioning scripts in the AI Dock repo:
# https://github.com/ai-dock/comfyui/tree/main/config/provisioning
HARBOR_COMFYUI_PROVISIONING    https://raw.githubusercontent.com/av/harbor/main/comfyui/provisioning.sh
```

##### Open WebUI

When running ComfyUI, Open WebUI will also be pre-configured to run a FLUX-based workflow for generating images.

Please refer to the [official Open WebUI documentation](https://docs.openwebui.com/tutorial/images/#setting-up-open-webui-with-comfyui) to adjust the image generation workflow.

> [!NOTE]
> Open WebUI will not work with ComfyUI when the authentication is enabled.

#### Documentation

- [ComfyUI Community Documentation](https://docs.comfy.org/get_started/introduction)
- [ComfyUI Community Manual](https://blenderneko.github.io/ComfyUI-docs/)
- [AI Dock Wiki](https://github.com/ai-dock/base-image/wiki)
- [Open WebUI and ComfyUI](https://docs.openwebui.com/tutorial/images/#setting-up-open-webui-with-comfyui)
