Deploying an InvokeAI App
Introduction
InvokeAI is an open-source Stable Diffusion toolkit for image generation, featuring a React front end and Python backend. Deploying InvokeAI with a Dockerfile on Klutch.sh provides reproducible builds, managed secrets, and persistent storage for models and outputs—all managed from klutch.sh/app. This guide covers installation, repository prep, a production-ready Dockerfile, deployment steps, Nixpacks overrides, and best practices for GPU-ready image generation.
Prerequisites
- A Klutch.sh account (create one)
- A GitHub repository containing your InvokeAI code/config (GitHub is the only supported git source)
- Docker familiarity and Python 3.10+ toolchain knowledge
- Access to NVIDIA GPU if you intend to run GPU-accelerated inference (ensure your Klutch.sh plan supports it)
- Storage capacity for model weights, embeddings, and generated assets
For platform basics, review the Quick Start.
Architecture and ports
- InvokeAI serves its web UI and API over HTTP; set the internal container port to
9090. - No additional TCP services are required by default. If you add databases or caches, run them as separate Klutch.sh TCP apps (external TCP port
8000, internal native ports). - Persistent storage is required for models, embeddings, and generated outputs.
Repository layout
invokeai/├── invokeai/ # Backend Python modules├── invokeai/frontend/ # React frontend├── configs/ # YAML configs, model paths, UI settings├── models/ # Model weights (mount as volume)├── outputs/ # Generated images (mount as volume)├── Dockerfile # Must be at repo root for auto-detection├── requirements.txt├── package.json├── pnpm-lock.yaml # or yarn.lock / package-lock.json└── .env.example # Template only; no secretsKeep secrets out of Git; store them in Klutch.sh environment variables.
Installation (local) and starter commands
Install dependencies locally before pushing to GitHub:
python -m venv .venvsource .venv/bin/activatepip install -r requirements.txtpnpm installpnpm buildinvokeai --web --host 0.0.0.0 --port 9090Optional helper start.sh for portability and Nixpacks fallback:
#!/usr/bin/env bashset -euo pipefailinvokeai --web --host 0.0.0.0 --port 9090Make it executable with chmod +x start.sh.
Dockerfile for InvokeAI (production-ready)
Place this Dockerfile at the repo root; Klutch.sh auto-detects it (no Docker selection in the UI):
FROM nvidia/cuda:12.2.2-cudnn8-runtime-ubuntu22.04
WORKDIR /app
# System dependenciesRUN apt-get update && apt-get install -y python3 python3-venv python3-pip git curl build-essential && \ rm -rf /var/lib/apt/lists/*
# Install Python dependenciesCOPY requirements.txt ./RUN python3 -m venv /opt/venv && \ /opt/venv/bin/pip install --no-cache-dir -r requirements.txt
# Frontend buildCOPY package.json pnpm-lock.yaml* yarn.lock* package-lock.json* ./RUN curl -fsSL https://get.pnpm.io/install.sh | sh - && \ export PATH=\"/root/.local/share/pnpm:$PATH\" && \ pnpm install --frozen-lockfile
COPY . .RUN export PATH=\"/root/.local/share/pnpm:$PATH\" && pnpm build
ENV PATH=\"/opt/venv/bin:/root/.local/share/pnpm:$PATH\" \ INVOKEAI_PORT=9090
EXPOSE 9090CMD ["invokeai", "--web", "--host", "0.0.0.0", "--port", "9090"]Notes:
- Use an NVIDIA CUDA base if you need GPU; for CPU-only, swap to
python:3.11-slimand remove CUDA tooling. - Keep
models/andoutputs/on volumes to preserve downloads and generations across deploys.
Environment variables (Klutch.sh)
Set these in the Klutch.sh app settings (Secrets tab) before deploying:
INVOKEAI_PORT=9090INVOKEAI_ROOT=/app(if your config expects a root path)INVOKEAI_MODEL_DIR=/app/modelsINVOKEAI_OUTPUT_DIR=/app/outputsPYTHONUNBUFFERED=1NODE_ENV=production
If you deploy without the Dockerfile and need Nixpacks overrides:
NIXPACKS_BUILD_CMD="pip install -r requirements.txt && pnpm install --frozen-lockfile && pnpm build"NIXPACKS_START_CMD=invokeai --web --host 0.0.0.0 --port 9090NIXPACKS_PYTHON_VERSION=3.11NIXPACKS_NODE_VERSION=18
These keep InvokeAI compatible with Nixpacks defaults when a Dockerfile is absent.
Attach persistent volumes
In Klutch.sh storage settings, add mount paths and sizes (no names required):
/app/models— required for model weights and embeddings./app/outputs— required for generated images and videos./app/configs— optional if you adjust configs at runtime.
Ensure these paths are writable inside the container.
Deploy InvokeAI on Klutch.sh (Dockerfile workflow)
- Push your repository (with the Dockerfile at the root) to GitHub.
- Open klutch.sh/app, create a project, and add an app.
- Connect the GitHub repository; Klutch.sh automatically detects the Dockerfile.
- Choose **HTTP** traffic for InvokeAI.
- Set the internal port to `9090`.
- Add the environment variables above (model/output paths and any `NIXPACKS_*` overrides if you temporarily deploy without the Dockerfile).
- Attach persistent volumes for `/app/models` and `/app/outputs` (and `/app/configs` if needed), selecting sizes that fit your models and generations.
- Deploy. Your InvokeAI UI and API will be reachable at `https://example-app.klutch.sh`; attach a custom domain if desired.
Health checks and production tips
- Add a
/healthor lightweight status route in your proxy to monitor uptime. - For GPU use, verify CUDA drivers and match the base image version to your hardware.
- Monitor disk usage on
/app/modelsand/app/outputs; resize volumes before they fill. - Pin Python/Node versions and lockfiles for reproducible builds.
- Enforce HTTPS at the edge and restrict access if your deployment hosts private models.
InvokeAI on Klutch.sh combines reproducible Docker builds with managed secrets, persistent model/output storage, and flexible HTTP/TCP routing. With the Dockerfile at the repo root and ports set to 9090 for the app (8000 externally for any TCP companions), you can deliver GPU-ready image generation without extra YAML or workflow overhead.