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

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

[![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-shgield]][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://raw.githubusercontent.com/comfyanonymous/ComfyUI/master/comfyui_screenshot.png)
</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#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

#### 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)/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#harbor-config):

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

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

# Docker image tag to use, can be set to
# "latest-rocm" or "latest-cpu" see:
# https://github.com/ai-dock/comfyui/pkgs/container/comfyui
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
COMFYUI_WORKSPACE              ./comfyui/workspace

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

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

# Additional arguments for the ComfyUI
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
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)
