Self-hosted • Privacy-first • No tracking
Home / Self-Hosted AI / ComfyUI Local Install Guide: Docker Compose Setup for Stable Diffusion in Your Homelab
Self-Hosted AI #homelab#docker-compose#self-hosted-ai#comfyui#stable-diffusion ⏱ 10 min • 👁 1 • Aug 31, 2026

ComfyUI Local Install Guide: Docker Compose Setup for Stable Diffusion in Your Homelab

Step-by-step Docker Compose guide to install ComfyUI v0.34.0 locally for Stable Diffusion, with advanced settings, common errors, and hardening tips.

AdSense — Top (970x90) • Responsive
ComfyUI Local Install Guide: Docker Compose Setup for Stable Diffusion in Your Homelab

ComfyUI Local Install Guide: Docker Compose Setup for Stable Diffusion in Your Homelab

Introduction

ComfyUI has become the go-to node-based interface for Stable Diffusion workflows, offering unmatched flexibility for generating and editing images. Unlike cloud-based services, self-hosting ComfyUI gives you full control over your data, models, and compute resources—essential for privacy-conscious users and homelab enthusiasts. With its modular design, you can craft complex pipelines, automate batch generation, and integrate custom nodes without leaving your own hardware.

This guide walks you through installing ComfyUI v0.34.0 (the latest official release as of August 2026) using Docker Compose. Docker Compose simplifies dependency management, ensures reproducibility, and allows you to run ComfyUI alongside other self-hosted services with minimal friction. By the end, you will have a production-ready ComfyUI instance accessible via your local network, with optional reverse proxy and SSL configuration.

We will cover prerequisites, a complete docker-compose.yml, environment configuration, model management, and common troubleshooting. We also include an optional hardening section for those who want to lock down their deployment. All commands are copy-paste ready, and every version is pinned via environment variables so you can update safely from a single .env file.

Whether you are a seasoned homelabber or new to self-hosted AI, this guide provides the exact steps to get ComfyUI running reliably. Let's dive in.

Prerequisites / Requirements

Before you begin, ensure your hardware and software meet the following minimum requirements. These are typical estimates—actual resource usage depends on model size, image resolution, and concurrent workflows.

Component Minimum Recommended Notes
CPU 4 cores 8+ cores Multi-threaded node processing benefits from more cores.
RAM 8 GB 16+ GB Loading large models (e.g., SDXL) can exceed 8 GB.
GPU NVIDIA GTX 1060 6GB NVIDIA RTX 3060 12GB+ ComfyUI uses CUDA; AMD/Intel GPUs require extra setup (ROCm/OpenCL).
Storage 10 GB free 50+ GB free Models (2-7 GB each), VAE, LoRAs, and output images accumulate quickly.
Software Docker 20.10+, Docker Compose v2, NVIDIA Container Toolkit (if GPU) Latest versions Install Docker from official docs, not distro packages.
OS Linux (Ubuntu 22.04 LTS tested) Any Linux distro macOS works but GPU passthrough is limited; Windows via WSL2 is possible but not covered here.

Important: If you plan to use GPU acceleration, install the NVIDIA Container Toolkit after Docker. On Ubuntu, run:

sudo apt-get update && sudo apt-get install -y nvidia-container-toolkit && sudo systemctl restart docker

For non-NVIDIA GPUs, refer to ComfyUI's official documentation for alternative runtime configurations.

Installation Steps

Step 1: Create Project Directory and .env File

Create a dedicated directory for ComfyUI and navigate into it. Then create a .env file to store all configuration variables. This keeps secrets out of your docker-compose.yml and makes version updates trivial.

mkdir -p ~/comfyui && cd ~/comfyui && touch .env

Edit the .env file with your preferred editor. At minimum, set the following variables. Replace your_secure_password with a strong password of your choice. Never commit this file to Git—add .env to your .gitignore if you use version control.

COMFYUI_VERSION=v0.34.0
COMFYUI_PORT=8188
COMFYUI_USER=1000
COMFYUI_GROUP=1000

Security warning: The .env file contains sensitive data. Keep it readable only by your user: chmod 600 ~/comfyui/.env.

Step 2: Create docker-compose.yml

Save the following docker-compose.yml in the same directory. It uses the official ComfyUI image (from the comfyui Docker Hub repository) and mounts necessary volumes for models, custom nodes, and outputs.

services:
  comfyui:
    image: comfyui/comfyui:${COMFYUI_VERSION:-latest}
    container_name: comfyui
    restart: unless-stopped
    ports:
      - "${COMFYUI_PORT:-8188}:8188"
    volumes:
      - ./models:/workspace/models
      - ./custom_nodes:/workspace/custom_nodes
      - ./output:/workspace/output
      - ./user:/workspace/user
    environment:
      - NVIDIA_VISIBLE_DEVICES=all
      - NVIDIA_DRIVER_CAPABILITIES=compute,utility
    user: "${COMFYUI_USER:-1000}:${COMFYUI_GROUP:-1000}"
    command: ["python", "main.py", "--listen", "0.0.0.0"]

Note: The comfyui/comfyui image is community-maintained. Always check the official GitHub releases page before pinning a version—the version above may be outdated by now. The image runs as user 1000:1000 by default; verify with id -u && id -g on your host and adjust the COMFYUI_USER and COMFYUI_GROUP variables accordingly.

Step 3: Create Required Directories

Create the directories referenced in the volumes. This ensures Docker doesn't create them as root, which would cause permission issues.

mkdir -p models custom_nodes output user && ls -la

Step 4: Pull and Start the Container

Now pull the image and start the container. The first pull may take a few minutes depending on your internet speed.

docker compose up -d && docker compose logs -f

Wait until you see a log line similar to Starting server or To see the GUI go to: http://0.0.0.0:8188. Press Ctrl+C to stop following logs.

Step 5: Verify the Web Interface

Open your browser and navigate to http://localhost:${COMFYUI_PORT:-8188}. You should see the ComfyUI canvas. If you are on a remote server, replace localhost with your server's IP address.

Step 6: Download a Stable Diffusion Model

ComfyUI does not include models by default. Download a model (e.g., SD 1.5 or SDXL) from Hugging Face or CivitAI and place it in the models/checkpoints directory (create it if missing).

mkdir -p models/checkpoints && cd models/checkpoints && wget -O v1-5-pruned-emaonly.safetensors https://huggingface.co/runwayml/stable-diffusion-v1-5/resolve/main/v1-5-pruned-emaonly.safetensors

After downloading, refresh the ComfyUI interface. The model should appear in the checkpoint loader node.

Step 7: Install Custom Nodes (Optional)

ComfyUI supports custom nodes for extra functionality. To install them, clone the repository into the custom_nodes directory and restart the container.

cd ~/comfyui/custom_nodes && git clone https://github.com/ltdrdata/ComfyUI-Manager.git && cd ~/comfyui && docker compose restart

Note: Always read the custom node's documentation for compatibility with your ComfyUI version.

Step 8: Set Up User Persistence (Optional)

The user volume stores UI settings, workflows, and user data. By default, it's mounted as ./user. Ensure it's writable by the container user.

sudo chown -R ${COMFYUI_USER:-1000}:${COMFYUI_GROUP:-1000} ~/comfyui/user

Step 9: Configure GPU Access (If Using NVIDIA)

If you have an NVIDIA GPU and installed the container toolkit, the environment variables in the compose file already enable GPU access. To verify, run:

docker exec comfyui nvidia-smi

You should see your GPU listed. If not, check that nvidia-container-toolkit is installed and Docker daemon is restarted.

Step 10: Enable API Access (For Automation)

ComfyUI exposes a REST API by default. To allow external automation, you need to set --enable-cors-header in the command. Modify the command in your docker-compose.yml:

    command: ["python", "main.py", "--listen", "0.0.0.0", "--enable-cors-header", "*"]

Then restart the container:

docker compose up -d --force-recreate

Step 11: Set Up Reverse Proxy (Advanced)

For secure remote access, place ComfyUI behind a reverse proxy like Nginx or Caddy. Below is a minimal Caddyfile example. Add this to your existing reverse proxy setup.

comfyui.example.com {
    reverse_proxy localhost:${COMFYUI_PORT:-8188}
}

Then run Caddy with Docker Compose as well. For Nginx, use a similar server block with proxy_pass http://localhost:8188;.

Step 12: Backup Your Configuration

Regularly back up the models, custom_nodes, and user directories. Use a cron job or a simple script. Example backup command:

tar -czf comfyui-backup-$(date +%Y%m%d).tar.gz models custom_nodes user .env && mv comfyui-backup-*.tar.gz ~/backups/

Advanced Configuration / Optimization

Reverse Proxy and SSL

For production use, always terminate TLS at your reverse proxy. With Caddy, SSL is automatic. With Nginx, use Let's Encrypt via certbot. Ensure WebSocket support is enabled (ComfyUI uses WebSockets for progress updates). For Nginx, add:

proxy_http_version 1.1;
proxy_set_header Upgrade $http_upgrade;
proxy_set_header Connection "upgrade";

Backups

Automate backups with a cron job. Store backups on a different disk or remote location. Test restoration periodically.

Security Hardening (Optional)

If you expose ComfyUI to the internet, consider these hardening measures. Warning: These settings may break functionality if not adapted to your environment. Test in a staging environment first.

    read_only: true
    tmpfs:
      - /tmp
    security_opt:
      - no-new-privileges:true
    cap_drop:
      - ALL
    cap_add:
      - NET_BIND_SERVICE
  • read_only: Makes the container filesystem read-only, reducing attack surface.
  • tmpfs: Provides writable temporary space for runtime operations.
  • cap_drop/cap_add: Removes unnecessary Linux capabilities. ComfyUI may need CHOWN, FOWNER, DAC_OVERRIDE to write to volumes—test thoroughly.

Also, set COMFYUI_USER to a non-root user inside the container (e.g., 1000:1000), and avoid running as root.

Troubleshooting

Common Error Likely Cause Solution
Permission denied when writing to models Volume directory owned by root Run sudo chown -R ${COMFYUI_USER:-1000}:${COMFYUI_GROUP:-1000} ~/comfyui/models
CUDA out of memory GPU memory insufficient Reduce batch size, use --lowvram flag, or switch to CPU mode with --cpu
Connection refused on port 8188 Container not fully started or port bind failed Check docker compose logs comfyui and docker ps
ModuleNotFoundError: No module named 'torch' Image missing dependencies Ensure you used the official image; try docker compose pull and recreate
WebSocket connection failed Reverse proxy not configured for WebSockets Add proxy_set_header Upgrade and Connection headers in Nginx
Model not appearing in UI Model file in wrong directory Place .safetensors in models/checkpoints and refresh browser cache
NVIDIA_DRIVER_CAPABILITIES not set GPU not passed to container Reinstall nvidia-container-toolkit and restart Docker

Conclusion

You now have a fully functional ComfyUI instance running via Docker Compose, ready for Stable Diffusion workflows. We covered directory setup, environment variables, GPU acceleration, and common pitfalls. Remember to keep your .env secure, back up your data, and check for updates regularly using the official GitHub releases page.

ComfyUI's flexibility makes it a cornerstone of any self-hosted AI toolkit. With this foundation, you can explore custom nodes, API automation, and even multi-GPU setups. The community is active—join forums and Discord to share workflows and learn from others.

FAQ

Q1: How do I update ComfyUI to a newer version?

Update the COMFYUI_VERSION variable in your .env file to the latest release tag from the official GitHub releases page, then run docker compose pull && docker compose up -d. Always read the release notes for breaking changes, especially regarding custom nodes.

Q2: Can I use ComfyUI with an AMD GPU?

Yes, but it requires extra setup. The official image is CUDA-focused; you may need to use a ROCm-enabled image or build from source. Check the official ComfyUI documentation for AMD support and use the appropriate Docker image or run with --cpu as a fallback.

Q3: How do I expose ComfyUI to the internet securely?

Use a reverse proxy with SSL, enable authentication (e.g., Basic Auth or a dedicated identity provider), and apply the optional hardening settings. Do not expose port 8188 directly unless you are on a trusted network. Also, consider using a VPN for remote access.

Q4: Where are my generated images stored?

The output volume maps to /workspace/output inside the container. By default, images are saved in subdirectories per workflow. You can change the output folder in the UI settings under Output Directory.

Q5: Why is my GPU not being used?

Check that nvidia-smi works inside the container. If not, ensure the NVIDIA Container Toolkit is installed and Docker was restarted. Also, verify that the NVIDIA_VISIBLE_DEVICES environment variable is set to all and that your GPU is compatible with the CUDA version in the image.


Always consult the official ComfyUI GitHub repository and Docker Hub page for the most current information.

AdSense — In-article (responsive)

Related Guides