Back to blog
November 5, 2026•35 views

How to Self-Host n8n on a VPS with Docker: A Step-by-Step Guide for Founders Who Want Automation Without Monthly SaaS Fees

n8nself-hostingdockerautomationvpsdevopsai automationsmall business
How to Self-Host n8n on a VPS with Docker: A Step-by-Step Guide for Founders Who Want Automation Without Monthly SaaS Fees

Most founders I talk to in Dhaka, Sydney, or Austin start with Zapier or Make, hit a task limit in week three, and then get a bill that reads like a phone number. The workflows are not exotic either. A lead form pushes to a CRM, an invoice goes out, a Slack message fires. That is it. You are paying per task for plumbing.

You can self-host n8n on a VPS for the price of a couple of coffees a month and keep the workflows, the data, and the execution history on hardware you control. I have run n8n in production on Docker and Kubernetes for client automation, and I have also cleaned up a few broken self-hosted installs where someone followed a half-finished blog post and lost their encryption key. This guide is the version I wish they had read: copy-paste Docker Compose, Postgres, SSL, backups, and the security steps that actually matter.

One honest caveat before we start. Self-hosting is not free, it is cheap. You trade a subscription for a small amount of operational care. If you cannot spare an hour a month for updates and backups, pay n8n Cloud and move on. If you can, read on.

The 60-second version

If you already know Docker, here is the whole thing:

  1. Spin up an Ubuntu 24.04 VPS with 2 vCPU and 4 GB RAM.
  2. Point a subdomain (say automation.yourdomain.com) at the VPS IP.
  3. Install Docker, create a non-root user, enable the firewall.
  4. Drop a docker-compose.yml with n8n, Postgres, and Caddy into /opt/n8n.
  5. docker compose up -d, open the subdomain, create the owner account.
  6. Set up a nightly pg_dump and copy it off the box.

Everything below is the detail and the reasoning.

Why self-host n8n at all?

The pitch for self-hosted automation for small business is simple: n8n's Community Edition has no execution cap. You pay for the server, not the tasks. For a business running a few thousand executions a month, the math is not close.

Option Rough monthly cost Execution limits Data location Your ops effort
n8n Cloud (Starter) ~$24+ Capped, scales with plan n8n's servers None
Zapier (Professional) ~$50+ Task-based, gets expensive fast Zapier's servers None
Make (Core) ~$10+ Operation-based Make's servers None
Self-hosted n8n on VPS $6 to $15 None (your hardware) Your VPS ~1 hour/month
Self-hosted n8n + managed DB $20 to $40 None Your cloud account ~2 hours/month

The costs above are ballpark and move around, so check current pricing on each vendor's site. The structural point stands: SaaS automation bills scale with volume, a VPS bill does not. When a workflow suddenly processes 40,000 rows during a data migration, Zapier sends you an overage notice and n8n just works a bit harder.

You also get things SaaS tools gate behind higher tiers: custom code nodes, self-hosted AI models, direct database access, and full control over where client data lives. For founders in Bangladesh handling local client data, or Australian businesses with privacy obligations, that control is worth real money. If you are weighing whether to run models on your own box too, my cost analysis of self-hosting AI models covers the trade-offs.

Which VPS do you actually need?

This is the section most tutorials skip, and it is the one that bites people. n8n is a Node.js app plus a database. It is not heavy, but it is not a Raspberry Pi project either. Memory is the constraint, not CPU.

Workload vCPU RAM Disk Notes
Solo founder, light workflows 1 2 GB 40 GB Works, but tight. Add swap.
Small team, Postgres, daily use 2 4 GB 80 GB The sweet spot. Start here.
Heavy AI/LLM nodes, big payloads 4 8 GB 160 GB LLM calls and file handling eat RAM.
Queue mode with workers 4+ 8 GB+ 160 GB+ Add Redis, split main and worker.

Provider-wise, I use and recommend a few depending on where you are:

  • Hetzner (Germany, US, Singapore): strong price-to-performance, though Singapore is the closest region for Bangladesh readers.
  • DigitalOcean and Vultr: more regions, including Sydney and Mumbai, which matters for latency from Australia and South Asia.
  • Contabo: cheap and large disks, but oversold at times. Fine for batch jobs, less fun for interactive use.
  • Local providers in Bangladesh: useful if data residency matters to your clients, but check uptime history before committing.

Pick a region close to your users and your data sources. If your CRM is in the US and your team is in Dhaka, the workflow latency is dominated by API round trips, not the VPS location, so do not overthink it.

Step 1: Prepare the server

Create an Ubuntu 24.04 LTS VPS, then SSH in as root and do the basics. A dedicated non-root user and a firewall are not optional.

# As root
adduser deploy
usermod -aG sudo deploy

# Copy your SSH key over for the new user
rsync --archive --chown=deploy:deploy ~/.ssh /home/deploy

# Basic firewall
apt update && apt upgrade -y
apt install -y ufw fail2ban
ufw allow OpenSSH
ufw allow 80
ufw allow 443
ufw enable

Then log out and back in as deploy. From here on, nothing runs as root except sudo commands you explicitly choose.

Install Docker using the official apt repo, which gives you predictable upgrades. These commands follow the official Docker Engine install docs for Ubuntu:

sudo apt install -y ca-certificates curl gnupg
sudo install -m 0755 -d /etc/apt/keyrings
curl -fsSL https://download.docker.com/linux/ubuntu/gpg | sudo gpg --dearmor -o /etc/apt/keyrings/docker.gpg
sudo chmod a+r /etc/apt/keyrings/docker.gpg
echo "deb [arch=$(dpkg --print-architecture) signed-by=/etc/apt/keyrings/docker.gpg] https://download.docker.com/linux/ubuntu $(. /etc/os-release && echo $VERSION_CODENAME) stable" | sudo tee /etc/apt/sources.list.d/docker.list > /dev/null
sudo apt update
sudo apt install -y docker-ce docker-ce-cli containerd.io docker-compose-plugin
sudo usermod -aG docker deploy

Log out and back in so the group change applies, then confirm with docker run hello-world.

Step 2: Point a subdomain at the VPS

In your DNS provider, add an A record for automation.yourdomain.com pointing at the VPS public IP. If you are on IPv6, add AAAA too. Wait for propagation (usually a few minutes) and check with dig automation.yourdomain.com.

Do this before starting the containers. Caddy will try to fetch a Let's Encrypt certificate on first boot, and it needs the DNS to resolve to succeed. If it fails, it retries, but you will see scary logs.

Step 3: The docker-compose.yml

This is the core of the n8n docker tutorial. It runs three services: n8n, Postgres, and Caddy for automatic HTTPS. Create /opt/n8n and put two files in it.

First, a .env file. Keep it out of git.

# /opt/n8n/.env
POSTGRES_USER=n8n
POSTGRES_PASSWORD=change_this_to_a_long_random_string
POSTGRES_DB=n8n

# Generate with: openssl rand -hex 32
N8N_ENCRYPTION_KEY=your_long_random_hex_string_here

N8N_HOST=automation.yourdomain.com
N8N_PROTOCOL=https
WEBHOOK_URL=https://automation.yourdomain.com/
GENERIC_TIMEZONE=Asia/Dhaka

Now the compose file:

# /opt/n8n/docker-compose.yml
services:
  postgres:
    image: postgres:16
    restart: unless-stopped
    environment:
      POSTGRES_USER: ${POSTGRES_USER}
      POSTGRES_PASSWORD: ${POSTGRES_PASSWORD}
      POSTGRES_DB: ${POSTGRES_DB}
    volumes:
      - postgres_data:/var/lib/postgresql/data
    healthcheck:
      test: ["CMD-SHELL", "pg_isready -U ${POSTGRES_USER} -d ${POSTGRES_DB}"]
      interval: 10s
      timeout: 5s
      retries: 5

  n8n:
    image: docker.n8n.io/n8nio/n8n:1.70.0
    restart: unless-stopped
    depends_on:
      postgres:
        condition: service_healthy
    environment:
      DB_TYPE: postgresdb
      DB_POSTGRESDB_HOST: postgres
      DB_POSTGRESDB_PORT: 5432
      DB_POSTGRESDB_DATABASE: ${POSTGRES_DB}
      DB_POSTGRESDB_USER: ${POSTGRES_USER}
      DB_POSTGRESDB_PASSWORD: ${POSTGRES_PASSWORD}
      N8N_ENCRYPTION_KEY: ${N8N_ENCRYPTION_KEY}
      N8N_HOST: ${N8N_HOST}
      N8N_PROTOCOL: ${N8N_PROTOCOL}
      WEBHOOK_URL: ${WEBHOOK_URL}
      GENERIC_TIMEZONE: ${GENERIC_TIMEZONE}
      N8N_SECURE_COOKIE: "true"
    volumes:
      - n8n_data:/home/node/.n8n
    ports:
      - "127.0.0.1:5678:5678"

  caddy:
    image: caddy:2
    restart: unless-stopped
    ports:
      - "80:80"
      - "443:443"
    volumes:
      - ./Caddyfile:/etc/caddy/Caddyfile:ro
      - caddy_data:/data
      - caddy_config:/config
    depends_on:
      - n8n

volumes:
  postgres_data:
  n8n_data:
  caddy_data:
  caddy_config:

And the Caddyfile:

automation.yourdomain.com {
    reverse_proxy n8n:5678
}

A few deliberate choices here, because they are the ones people get wrong:

  • Pin the n8n image tag (1.70.0 here, check the current release before you deploy). latest will one day upgrade you into a breaking change at 3 a.m. Pin, then upgrade on purpose.
  • Bind n8n to 127.0.0.1 only. Caddy reaches it over the internal Docker network. Nothing should expose port 5678 to the internet.
  • Postgres from the start. SQLite is fine for a laptop demo, not for production. You want real backups and no lock issues.
  • Caddy instead of Nginx because it handles certificates automatically with almost no config. If you already run Nginx or Traefik, swap it, the rest is unchanged.

Step 4: Start it up

cd /opt/n8n
docker compose up -d
docker compose logs -f caddy

Watch Caddy logs until you see the certificate obtained successfully. Then open https://automation.yourdomain.com. You should get the n8n setup screen. Create the owner account immediately, with a strong password. n8n also supports two-factor authentication (TOTP) for the owner account, so enable it if your version offers it.

If the page does not load, check three things in order: DNS resolves to the right IP, ports 80 and 443 are open in ufw, and the n8n container is healthy with docker compose ps.

Step 5: Lock it down

This is the section I care most about, because a self-hosted automation server holds API keys for your CRM, email, and payment tools. Treat it like a password vault.

  • Never lose the encryption key. N8N_ENCRYPTION_KEY encrypts every stored credential. Lose it and your credentials are unrecoverable. Back it up somewhere separate from the server, like a password manager.
  • Keep the firewall closed. Only 22, 80, and 443. Verify with sudo ufw status.
  • Run fail2ban on SSH. It is installed; enable the sshd jail.
  • Disable password SSH login once your key works. Edit /etc/ssh/sshd_config, set PasswordAuthentication no, restart sshd.
  • Use a long Postgres password and never expose the Postgres port. In the compose above it is internal only, which is correct.
  • Turn on user management and keep the user list short. n8n's user management lets you control who has editor access; enterprise tiers add SSO. Anyone with a login can read credentials through the UI, so limit access deliberately.

If you are wiring n8n into a stack that handles auth or multi-tenant routing, the same hardening instincts apply as in Next.js middleware for multi-tenant SaaS.

Step 6: Backups that actually restore

A backup you have never restored is a hope, not a backup. Two things need saving: the Postgres database and the n8n data volume (which holds the encryption key file and any local files). Since the key is in .env, back that up too.

A simple nightly script:

#!/usr/bin/env bash
# /opt/n8n/backup.sh
set -euo pipefail
STAMP=$(date +%F-%H%M)
DEST=/opt/n8n/backups
mkdir -p "$DEST"

docker compose -f /opt/n8n/docker-compose.yml exec -T postgres \
  pg_dump -U n8n n8n | gzip > "$DEST/n8n-db-$STAMP.sql.gz"

# Keep 14 days
find "$DEST" -name 'n8n-db-*.sql.gz' -mtime +14 -delete

Add it to cron with crontab -e:

0 2 * * * /opt/n8n/backup.sh >> /var/log/n8n-backup.log 2>&1

Then copy those dumps off the box. A backup on the same VPS dies with the VPS. Use rclone to push to S3, Backblaze B2, or Google Drive. Restoring is gunzip -c file.sql.gz | docker compose exec -T postgres psql -U n8n n8n.

Step 7: Upgrades without drama

Because you pinned the image tag, upgrades are intentional. The safe sequence:

  1. Check the n8n release notes for breaking changes and database migrations.
  2. Run a backup manually and confirm the file exists.
  3. Edit the image tag in docker-compose.yml.
  4. docker compose pull && docker compose up -d.
  5. Watch logs, then test one workflow end to end.

If something breaks, change the tag back and up -d again. The database may have migrated, so this is why you read release notes first and keep backups.

When you outgrow a single container

One n8n container handles a surprising amount. When you start seeing slow executions or memory pressure, move to queue mode: a main instance, Redis, and one or more worker containers. That is a bigger topic, but the shape is the same compose file with EXECUTIONS_MODE=queue, a Redis service, and a n8n worker command. If you are processing tens of thousands of executions a day, it is worth doing properly, and it is the kind of thing I set up for clients on AWS and Kubernetes. If you are running n8n on AWS, the pitfalls in my n8n AWS setup guide will save you a weekend.

Common problems and fixes

  • Webhooks point to localhost. Your WEBHOOK_URL is wrong. It must be the public HTTPS URL.
  • SSL never issues. DNS not propagated, or port 80 blocked. Caddy needs port 80 for the HTTP challenge.
  • Container restarts in a loop. Usually Postgres not ready or a wrong password. Check docker compose logs postgres.
  • Credentials show as "could not decrypt". The encryption key changed or was lost. This is the one that ruins your week, so back the key up.
  • Out of memory kills. Add swap or resize the VPS. LLM and large file nodes are the usual culprits.

Is self-hosting right for you?

If you are a founder weighing this, ask one question: do you have someone who can spend an hour a month on updates and backups? If yes, self-host n8n on a VPS and stop paying per task. If no, n8n Cloud is a fair deal and you should take it. There is no prize for running your own server badly.

For teams that want the middle path, a managed platform like Coolify or Dokploy on the same VPS gives you a UI for deploys and backups without hand-editing compose files. It is a reasonable shortcut, just understand what it is doing under the hood so you can debug it.

I build and maintain self-hosted automation stacks for founders across Bangladesh, Australia, the US, Canada, and New Zealand, and I am happy to review your setup or take the ops off your plate. If you would rather learn it yourself, the compose file above is a solid starting point. Either way, own your automation.

Frequently asked questions

Can I self-host n8n on a cheap $6 VPS?

Yes, for light use. A 1 vCPU, 2 GB VPS runs n8n with Postgres fine for solo founders with a handful of workflows. Add swap and watch memory. Once you run heavy AI nodes or many concurrent executions, move to 2 vCPU and 4 GB.

Do I lose my workflows if I stop paying n8n?

No. On a self-hosted install your workflows and credentials live in your own Postgres database and data volume. There is no n8n subscription to lapse. Just keep backups, especially the encryption key, or stored credentials become unreadable.

How is self-hosted n8n different from n8n Cloud?

Same software, different owner. n8n Cloud handles servers, updates, and backups for a monthly fee with execution limits by plan. Self-hosting puts that work on you but removes execution caps and keeps data on your infrastructure.

Is self-hosted n8n secure enough for client data?

It can be, if you do the basics: firewall, non-root user, HTTPS via Caddy, strong Postgres password, and a backed-up encryption key. The main risk is human, not the software, so limit who has editor access and keep the server patched.

Share this post

Native Web Share is available on mobile, so that share sheet includes Instagram and any other app you have installed.

Let's Connect

Get In Touch

Let's build something premium together.

Contact info

Follow me
Chat on WhatsApp