Deploying a LobeChat App
Introduction
LobeChat is an open-source, Next.js-based chatbot interface for LLMs. Deploying LobeChat with a Dockerfile on Klutch.sh provides reproducible builds, managed secrets, and persistent storage for chats and settings—all configured from klutch.sh/app. This guide covers installation, repository prep, a production-ready Dockerfile, deployment steps, Nixpacks overrides, sample API usage, and production tips.
Prerequisites
- A Klutch.sh account (create one)
- A GitHub repository containing your LobeChat code/config (GitHub is the only supported git source)
- Docker familiarity and Node.js 18+ knowledge
- MongoDB credentials (required) and optional Redis for caching
- API keys for LLM providers (OpenAI, Azure, etc.) as needed
For platform onboarding, see the Quick Start.
Architecture and ports
- LobeChat serves HTTP; set the internal container port to
3000. - MongoDB and Redis should run as separate Klutch.sh TCP apps, exposed on port
8000, and connect internally on27017and6379. - Persistent storage is recommended for user data and logs.
Repository layout
lobechat/├── Dockerfile # Must be at repo root for auto-detection├── package.json├── pnpm-lock.yaml # or yarn.lock / package-lock.json├── .env.example # Template only; no secrets├── public/ # Static assets├── uploads/ # Optional uploads/logs (mount as volume)└── README.mdKeep secrets out of Git; store them in Klutch.sh environment variables.
Installation (local) and starter commands
Install dependencies and run locally before pushing to GitHub:
pnpm installpnpm buildpnpm start -- --port 3000Optional helper start.sh for portability and Nixpacks fallback:
#!/usr/bin/env bashset -euo pipefailpnpm prisma migrate deploy || trueexec pnpm start -- --port 3000Make it executable with chmod +x start.sh.
Dockerfile for LobeChat (production-ready)
Place this Dockerfile at the repo root; Klutch.sh auto-detects it (no Docker selection in the UI):
FROM node:18-alpine AS buildWORKDIR /app
COPY package.json pnpm-lock.yaml* yarn.lock* package-lock.json* ./RUN corepack enableRUN pnpm install --frozen-lockfile
COPY . .RUN pnpm build
FROM node:18-alpineWORKDIR /appENV NODE_ENV=production PORT=3000
COPY --from=build /app /appRUN corepack enable && pnpm install --prod --frozen-lockfile
EXPOSE 3000CMD ["pnpm", "start", "--", "--port", "3000"]Notes:
- Add build tools (
apk add --no-cache python3 make g++) in the build stage if native modules are required. - Ensure
.envsecrets are injected via Klutch.sh, not committed.
Environment variables (Klutch.sh)
Set these in the Klutch.sh app settings (Secrets tab) before deploying:
NODE_ENV=productionPORT=3000MONGODB_URI=mongodb://<user>:<password>@<host>:<port>/<db>REDIS_URL=redis://<user>:<password>@<host>:<port>(if using Redis)NEXTAUTH_URL=https://example-app.klutch.shNEXTAUTH_SECRET=<secure-nextauth-secret>JWT_SECRET=<secure-jwt-secret>- Provider keys (e.g.,
OPENAI_API_KEY,AZURE_OPENAI_ENDPOINT, etc.) as required by your flows
If you deploy without the Dockerfile and need Nixpacks overrides:
NIXPACKS_BUILD_CMD=pnpm install --frozen-lockfile && pnpm buildNIXPACKS_START_CMD=pnpm start -- --port 3000NIXPACKS_NODE_VERSION=18
These keep LobeChat 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/uploads— optional for stored conversations/assets./app/logs— optional if you persist logs on disk.
Ensure these paths are writable inside the container.
Deploy LobeChat 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 LobeChat.
- Set the internal port to
3000. - Add the environment variables above (MongoDB/Redis URLs, NextAuth/JWT secrets, provider keys, and any
NIXPACKS_*overrides if you temporarily deploy without the Dockerfile). - Attach persistent volumes for
/app/uploads(and/app/logsif used), choosing sizes that fit your storage needs. - Deploy. Your LobeChat instance will be reachable at
https://example-app.klutch.sh; attach a custom domain if desired.
Sample API usage
Send a prompt to LobeChat’s API (replace placeholders):
curl -X POST "https://example-app.klutch.sh/api/chat" \ -H "Content-Type: application/json" \ -H "Authorization: Bearer <token>" \ -d '{"message": "Hello from Klutch.sh!"}'Health checks and production tips
- Add a reverse proxy probe to
/api/healthor a lightweight status route. - Enforce HTTPS at the edge; forward HTTP to port 3000 internally.
- Keep lockfiles committed and Node version pinned; test upgrades before applying.
- Monitor MongoDB/Redis performance and tune connection pools.
- Rotate secrets regularly; store them only in Klutch.sh secrets.
- Track disk usage on uploads/logs and resize volumes before they fill.
LobeChat on Klutch.sh combines reproducible Docker builds with managed secrets, optional persistent storage, and flexible HTTP/TCP routing. With the Dockerfile at the repo root and port 3000 configured, you can deliver secure, scalable chatbot experiences without extra YAML or workflow overhead.