# Docker Compose

This repository includes a `docker-compose.yml` file to simplify running ComfyUI with Docker.

## Docker Volumes vs. Local Directories

By default, the `docker-compose.yml` file uses a Docker-managed volume named `workspace_data`. This volume stores all of ComfyUI's data, including models, inputs, and outputs. This is the most straightforward way to get started, but it can be less convenient if you want to manage these files directly from your host machine.

For more direct control, you can configure Docker Compose to use local directories (bind mounts) instead. This maps folders on your host machine directly into the container.

To switch to using local directories, edit `docker-compose.yml`:

1.  In both the `backend` and `frontend` services, replace `- workspace_data:/workspace` with the specific local directories you want to mount. For example:

    ```yaml
    services:
      backend:
        volumes:
          # - workspace_data:/workspace # Comment out or remove this line
          - ./models:/workspace/models
          - ./custom_nodes:/workspace/custom_nodes
          - ./output:/workspace/output
          - ./input:/workspace/input
      ...
      frontend:
        volumes:
          # - workspace_data:/workspace # Comment out or remove this line
          - ./models:/workspace/models
          - ./custom_nodes:/workspace/custom_nodes
          - ./output:/workspace/output
          - ./input:/workspace/input
    ```

2.  At the bottom of the file, remove or comment out the `workspace_data: {}` definition under `volumes`.

    ```yaml
    volumes:
      # workspace_data: {} # Comment out or remove this line
    ```

    Before running `docker compose up`, make sure the local directories (`./models`, `./custom_nodes`, etc.) exist in the same directory as your `docker-compose.yml` file.

The example `docker-compose` file contains other configuration settings. You can also use bind-mount volumes in the `volumes` key of the whole compose file. Read it carefully.

## Running with Docker Compose

### Linux

Before you begin, you must have the [NVIDIA Container Toolkit](https://docs.nvidia.com/datacenter/cloud-native/container-toolkit/latest/install-guide.html) for Docker installed to enable GPU acceleration.

### Starting the Stack

```shell
docker compose up
```

# Containers

## NVIDIA (CUDA)

```shell
docker pull ghcr.io/hiddenswitch/comfyui:latest-cuda
```

**Linux:**
```shell
docker run -p "8188:8188" -v $(pwd):/workspace -w "/workspace" --rm -it --gpus=all --ipc=host ghcr.io/hiddenswitch/comfyui:latest-cuda
```

**Windows (Docker Desktop with WSL2):**
```powershell
docker run -p "8188:8188" -v ${PWD}:/workspace -w "/workspace" --rm -it --gpus=all --ipc=host ghcr.io/hiddenswitch/comfyui:latest-cuda
```

The `--gpus=all` flag passes all NVIDIA GPUs into the container. This requires the [NVIDIA Container Toolkit](https://docs.nvidia.com/datacenter/cloud-native/container-toolkit/latest/install-guide.html) on Linux, or Docker Desktop with WSL2 GPU support on Windows.

## AMD (ROCm)

ROCm GPU passthrough uses device nodes instead of `--gpus`. This is Linux-only.

```shell
docker pull ghcr.io/hiddenswitch/comfyui:latest-rocm
```

**Linux:**
```shell
docker run -p "8188:8188" -v $(pwd):/workspace -w "/workspace" --rm -it --device /dev/kfd --device /dev/dri --group-add video --ipc=host ghcr.io/hiddenswitch/comfyui:latest-rocm
```

The `--device /dev/kfd --device /dev/dri` flags pass the AMD GPU kernel driver and render nodes into the container. `--group-add video` grants the necessary permissions to access the GPU.
