Skip to content

Deploying an Immich App

Introduction

Immich is an open-source, self-hosted photo and video backup platform built with NestJS and TypeScript. Deploying Immich with a Dockerfile on Klutch.sh delivers reproducible builds, managed secrets, and persistent storage for media—all from klutch.sh/app. This guide covers installation, repository prep, a production-ready Dockerfile, deployment steps, Nixpacks overrides, and best practices for performance and durability.


Prerequisites

  • A Klutch.sh account (create one)
  • A GitHub repository containing your Immich code/config (GitHub is the only supported git source)
  • Docker familiarity and Node.js 18+ for local testing
  • PostgreSQL (with PostGIS) and Redis credentials
  • Adequate persistent storage for photo/video uploads

For platform onboarding, see the Quick Start.


Architecture and ports

  • Immich’s API and web UI run over HTTP; set the internal container port to 3001 (common for the NestJS server).
  • PostgreSQL + PostGIS and Redis should run as separate Klutch.sh TCP apps. Expose them on port 8000 and connect internally on 5432 (Postgres) and 6379 (Redis).
  • Persistent storage is required for upload (media) and recommended for cache/thumbnails.

Repository layout

immich/
├── apps/server/ # NestJS backend
├── apps/web/ # Next.js web client
├── upload/ # Media storage (mount as volume)
├── 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
└── README.md

Keep secrets out of Git; store them in Klutch.sh environment variables.


Installation (local) and starter commands

Install dependencies and test locally before pushing to GitHub:

Terminal window
pnpm install
pnpm build
pnpm start --filter @immich/server -- --port 3001

If you use migrations, add:

Terminal window
pnpm prisma migrate deploy

Optional helper start.sh for portability and Nixpacks fallback:

#!/usr/bin/env bash
set -euo pipefail
pnpm prisma migrate deploy || true
pnpm start --filter @immich/server -- --port 3001

Make it executable with chmod +x start.sh.


Dockerfile for Immich (production-ready)

Place this Dockerfile at the repo root; Klutch.sh auto-detects it (no Docker toggle in the UI):

FROM node:18-alpine AS build
WORKDIR /app
COPY package.json pnpm-lock.yaml* yarn.lock* package-lock.json* ./
RUN corepack enable
RUN pnpm install --frozen-lockfile
COPY . .
RUN pnpm build
FROM node:18-alpine
WORKDIR /app
ENV NODE_ENV=production PORT=3001
COPY --from=build /app /app
RUN corepack enable && pnpm install --prod --frozen-lockfile
EXPOSE 3001
CMD ["pnpm", "start", "--filter", "@immich/server", "--", "--port", "3001"]

Notes:

  • If you need native dependencies (e.g., sharp), add build tools in the build stage: apk add --no-cache python3 make g++.
  • Keep upload/ writable and mount it as a volume for media durability.

Environment variables (Klutch.sh)

Set these in the Klutch.sh app settings (Secrets tab) before deploying:

  • NODE_ENV=production
  • PORT=3001
  • APP_BASE_URL=https://example-app.klutch.sh
  • DATABASE_URL=postgres://<user>:<password>@<host>:<port>/<db>
  • REDIS_URL=redis://<user>:<password>@<host>:<port>
  • IMMICH_UPLOAD_LOCATION=/app/upload
  • JWT_SECRET=<jwt-secret>
  • IMMICH_ENABLE_MAP=true (optional feature flag)

If you deploy without the Dockerfile and need Nixpacks overrides:

  • NIXPACKS_BUILD_CMD=pnpm install --frozen-lockfile && pnpm build
  • NIXPACKS_START_CMD=pnpm start --filter @immich/server -- --port 3001
  • NIXPACKS_NODE_VERSION=18

These keep Immich 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/upload — required for photos/videos.
  • /app/.cache — optional for cached thumbnails if your build writes there.

Ensure these paths are writable inside the container.


Deploy Immich on Klutch.sh (Dockerfile workflow)

  1. Push your repository (with the Dockerfile at the root) to GitHub.
  2. Open klutch.sh/app, create a project, and add an app.
  3. Connect the GitHub repository; Klutch.sh automatically detects the Dockerfile.
  4. Choose HTTP traffic for Immich.
  5. Set the internal port to 3001.
  6. Add the environment variables above (database, Redis, upload path, JWT secret, and any NIXPACKS_* overrides if you temporarily deploy without the Dockerfile).
  7. Attach persistent volumes for /app/upload (and /app/.cache if used), selecting sizes that fit your media retention plan.
  8. Deploy. Your Immich instance will be reachable at https://example-app.klutch.sh; attach a custom domain if desired.

For PostgreSQL/PostGIS or Redis on Klutch.sh, create separate TCP apps, expose them on port 8000, and point DATABASE_URL or REDIS_URL to those endpoints (internal ports 5432/6379).


Health checks and production tips

  • Add a lightweight /health endpoint that checks DB/Redis connectivity.
  • Enable HTTPS at the edge; forward HTTP to port 3001 internally.
  • Monitor volume usage for /app/upload and resize before it fills.
  • Keep lockfiles committed and Node versions pinned for reproducible builds.
  • Back up your database and media regularly; do not rely on container filesystems for durability.

Immich on Klutch.sh combines reproducible Docker builds with managed secrets, persistent media storage, and flexible HTTP/TCP routing. With the Dockerfile at the repo root and ports set to 3001 for the app (8000 externally for TCP databases or caches), you can deliver a reliable, self-hosted photo and video experience without extra YAML or workflow overhead.