Home / Software / n8n / How to Install n8n with Docker: Self-Hosted Setup Guide

How to Install n8n with Docker: Self-Hosted Setup Guide

How to Install n8n with Docker: Self-Hosted Setup Guide

n8n is a powerful, open-source workflow automation tool that lets you connect apps, automate tasks, and build complex integrations — all without handing your data over to a third-party SaaS platform. Self-hosting n8n on your own server gives you full control over your workflows and credentials, and it is far simpler to set up than most people expect. If you can run a few terminal commands and have a Linux server available, you can have n8n running in under fifteen minutes using Docker Compose.

Prerequisites

Before you begin, make sure you have the following in place:

  • A Linux server running Ubuntu 22.04 or 24.04 (a local home server or a cloud VPS both work)
  • Docker and Docker Compose installed (Docker Engine 20.10 or later recommended)
  • A domain name pointed at your server (optional but strongly recommended for production use)
  • Basic familiarity with the command line

For a VPS, a £5/month instance from Hetzner (German-based, GDPR-friendly, and excellent value) is more than sufficient to run n8n comfortably. If data sovereignty within the UK is a priority, providers such as Mythic Beasts or Krystal offer UK-based hosting. A 2GB RAM, 2 vCPU server is a sensible starting point.

Step 1: Create a Directory for n8n

SSH into your server and create a dedicated directory to hold your n8n configuration files:

mkdir ~/n8n && cd ~/n8n

Keeping everything in one place makes backups and updates straightforward.

Step 2: Create the Docker Compose File

Inside the ~/n8n directory, create a file called docker-compose.yml:

nano docker-compose.yml

Paste in the following configuration, replacing the placeholder values with your own:

version: "3.8"

services:
  n8n:
    image: n8nio/n8n
    container_name: n8n
    restart: unless-stopped
    ports:
      - "5678:5678"
    environment:
      - N8N_HOST=your-domain.com
      - N8N_PORT=5678
      - N8N_PROTOCOL=https
      - WEBHOOK_URL=https://your-domain.com/
      - N8N_BASIC_AUTH_ACTIVE=true
      - N8N_BASIC_AUTH_USER=admin
      - N8N_BASIC_AUTH_PASSWORD=your-strong-password
      - GENERIC_TIMEZONE=Europe/London
    volumes:
      - n8n_data:/home/node/.n8n

volumes:
  n8n_data:

A few notes on the environment variables:

  • N8N_HOST — set this to your domain name, or to your server’s IP address if you are not using a domain
  • N8N_PROTOCOL — use http if you are running locally without SSL; use https once you have a reverse proxy with SSL in place
  • WEBHOOK_URL — the full public URL n8n will use to receive webhook calls; must match your protocol and domain
  • N8N_BASIC_AUTH_ACTIVE — enables simple username and password protection; highly recommended if your instance is publicly accessible
  • GENERIC_TIMEZONE — set to Europe/London for UK users so that scheduled workflows fire at the correct local time

Save the file and exit (Ctrl+X, then Y, then Enter in nano).

Step 3: Start n8n

With your compose file in place, start n8n in detached mode:

docker compose up -d

Docker will pull the latest n8nio/n8n image and start the container in the background. You can check that it is running with:

docker compose ps

To view live logs during startup:

docker compose logs -f

Step 4: Access n8n in Your Browser

Once the container is running, open your browser and navigate to:

  • Local or home server: http://localhost:5678
  • Remote VPS (no domain): http://your-server-ip:5678
  • With a domain and reverse proxy: https://your-domain.com

If you enabled basic auth, you will be prompted for the username and password you set in the compose file before reaching the n8n interface.

Step 5: Create Your Owner Account

On first launch, n8n will walk you through a short setup wizard to create the owner account. Enter your name, email address, and a password for the n8n application itself. This is separate from the basic auth credentials — it is your n8n user account used to log in to the workflow editor.

Once the account is created, you will land on the n8n dashboard and can start building workflows immediately.

Understanding the Data Directory

All of your n8n data — workflows, credentials, settings, and execution logs — is stored inside the Docker volume mounted at /home/node/.n8n inside the container. In the compose file above, this is mapped to a named Docker volume called n8n_data, which Docker manages on your host at /var/lib/docker/volumes/n8n_n8n_data.

This directory is critical. If you lose it, you lose everything. Back it up regularly.

Backing Up Your n8n Data

A simple backup strategy is to copy the volume data to a safe location on a schedule. First, find where Docker stores the volume:

docker volume inspect n8n_n8n_data

Then copy the contents to a backup location:

sudo cp -r /var/lib/docker/volumes/n8n_n8n_data/_data ~/n8n-backup-$(date +%Y%m%d)

You can automate this with a cron job, or sync the backup directory to a remote location using rsync or a tool like Restic. At a minimum, back up before every update.

Updating n8n

Keeping n8n up to date is straightforward with Docker Compose. From your ~/n8n directory, run:

docker compose pull && docker compose up -d

This pulls the latest n8nio/n8n image and recreates the container with the new version. Your data is preserved in the volume and will not be affected by the update. It is good practice to check the n8n release notes before updating, particularly for major version changes that may include breaking changes.

Putting n8n Behind a Reverse Proxy (SSL)

Running n8n directly on port 5678 is fine for local or home server use, but for a production setup accessible from the internet, you should place it behind a reverse proxy such as Nginx or Caddy. A reverse proxy handles SSL termination, gives you a clean HTTPS URL, and is essential if you plan to use webhooks reliably.

Caddy in particular is beginner-friendly as it provisions and renews Let’s Encrypt certificates automatically. Once your reverse proxy is in place, update N8N_PROTOCOL to https and WEBHOOK_URL to your full HTTPS address in the compose file, then restart the container with docker compose up -d.

For a full walkthrough of setting this up, see our dedicated guide on configuring Nginx and Caddy as a reverse proxy for n8n.

Running n8n on a Home Server

n8n works perfectly on a home server — a spare PC, a NUC, or even a Raspberry Pi 4 with 4GB RAM. The advantage of a home server is zero ongoing cost and complete local control. The trade-off is that webhooks from external services require your home IP to be reachable from the internet, which means either a static IP from your ISP, a DDNS service, or a tunnel tool such as Cloudflare Tunnel.

For anything requiring reliable external webhook access — Stripe, GitHub, or third-party APIs calling back to n8n — a small VPS is the easier choice. Hetzner’s CAX11 ARM instance (approximately £4/month at the time of writing) runs n8n without any issues and keeps your data within the EU under GDPR-compliant infrastructure.

Whichever approach you choose, the Docker Compose setup above is identical — only the networking and domain configuration differs.