Skip to content

Deploying an n8n App

Introduction

n8n is an open-source workflow automation platform built on Node.js. Deploying n8n with a Dockerfile on Klutch.sh provides reproducible builds, managed secrets, and persistent storage for credentials and workflows—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 (sign up)
  • A GitHub repository containing your n8n Dockerfile (GitHub is the only supported git source)
  • Database credentials if you externalize data (PostgreSQL recommended); otherwise, use the default SQLite file storage
  • Domain and TLS for secure access

For onboarding, see the Quick Start.


Architecture and ports

  • n8n serves HTTP on internal port 5678; choose HTTP traffic.
  • Persistent storage is required for credentials, workflows, and SQLite (if used).
  • For Postgres deployments, run the database as a separate Klutch.sh TCP app on port 8000 and connect on 5432.

Repository layout

n8n/
├── Dockerfile # Must be at repo root for auto-detection
└── README.md

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


Installation (local) and starter commands

Validate locally before pushing to GitHub:

Terminal window
docker build -t n8n-local .
docker run -p 5678:5678 -e N8N_BASIC_AUTH_USER=admin -e N8N_BASIC_AUTH_PASSWORD=changeme n8n-local

Dockerfile for n8n (production-ready)

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

FROM n8nio/n8n:latest
ENV N8N_PORT=5678
EXPOSE 5678
CMD ["n8n", "start"]

Notes:

  • Pin the image tag for stability (e.g., n8nio/n8n:1.41.x) and upgrade intentionally.
  • If you mount custom nodes or assets, add COPY steps and ensure writable paths.

Environment variables (Klutch.sh)

Set these in Klutch.sh before deploying:

  • N8N_PORT=5678
  • WEBHOOK_URL=https://example-app.klutch.sh/
  • N8N_HOST=example-app.klutch.sh
  • N8N_PROTOCOL=https
  • N8N_BASIC_AUTH_ACTIVE=true
  • N8N_BASIC_AUTH_USER=<admin-user>
  • N8N_BASIC_AUTH_PASSWORD=<admin-password>
  • For Postgres: DB_TYPE=postgresdb, DB_POSTGRESDB_HOST=<db-host>, DB_POSTGRESDB_PORT=5432, DB_POSTGRESDB_DATABASE=<db-name>, DB_POSTGRESDB_USER=<db-user>, DB_POSTGRESDB_PASSWORD=<db-password>
  • For SQLite (default): DB_TYPE=sqlite
  • Optional encryption key: N8N_ENCRYPTION_KEY=<secure-random>

If you deploy without the Dockerfile and need Nixpacks overrides:

  • NIXPACKS_START_CMD=n8n start
  • NIXPACKS_NODE_VERSION=18

Attach persistent volumes

In Klutch.sh storage settings, add mount paths and sizes (no names required):

  • /home/node/.n8n — credentials, workflows, and SQLite data.
  • /home/node/.n8n/logs — optional logs if you store them on disk.

Ensure these paths are writable inside the container.


Deploy n8n 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. Select HTTP traffic and set the internal port to 5678.
  4. Add the environment variables above, including database settings (Postgres or SQLite) and basic auth credentials.
  5. Attach persistent volumes for /home/node/.n8n (and /home/node/.n8n/logs if used) sized for your workflow data.
  6. Deploy. Access your n8n instance at https://example-app.klutch.sh and start building workflows.

Sample API usage

List workflows (requires basic auth/token):

Terminal window
curl -X GET "https://example-app.klutch.sh/rest/workflows" \
-u "<admin-user>:<admin-password>"

Health checks and production tips

  • Add an HTTP probe to /healthz or / for readiness.
  • Enforce HTTPS at the edge; forward internally to port 5678.
  • Use Postgres for production; keep credentials and encryption keys in Klutch.sh secrets and rotate them regularly.
  • Monitor volume usage on /home/node/.n8n; resize before it fills.
  • Pin image versions and test upgrades in staging before production.

n8n on Klutch.sh combines reproducible Docker builds with managed secrets, persistent storage, and flexible HTTP/TCP routing. With the Dockerfile at the repo root, port 5678 configured, and your database set, you can run secure, scalable automations without extra YAML or workflow overhead.