Skip to content

Self-Hosting n8n with Docker: Your Complete UK Setup Guide

This page may contain affiliate links.

If you're running a digital side hustle, you're probably already a dab hand at finding ways to streamline tasks. That's where n8n, the powerful workflow automation tool, comes in. Think of it as a supercharged Zapier or Make.com, but with a crucial difference: you can self-host it. Self-hosting n8n gives you complete control, enhanced privacy, and significant cost savings, especially as your automation needs grow. No more worrying about monthly subscription tiers or data leaving your servers!

This comprehensive guide is designed for the UK-based entrepreneur, covering everything you need to know to get n8n up and running on your own server using Docker. We'll walk through choosing your hardware, setting up Docker, configuring n8n with a persistent database, and securing it with a reverse proxy and SSL. Let's get cracking and liberate your workflows!

Why Self-Host n8n? The Sheddad.Tech Advantage

Before we dive into the nitty-gritty, let's quickly touch on why self-hosting n8n is such a smart move for your side hustle:

  • Cost Savings: Cloud-hosted n8n instances or alternatives can get pricey, especially if you have complex or high-volume workflows. A basic Virtual Private Server (VPS) might cost you around £5-£15 a month, or a one-off payment for a Raspberry Pi. The cost difference can be substantial over time.
  • Complete Control & Flexibility: You own the server, you own the data. No vendor lock-in, no arbitrary limits. You can configure n8n exactly how you need it, integrate custom nodes, and scale resources on your terms.
  • Enhanced Privacy & Security: For sensitive data or GDPR compliance, keeping your workflows on your own infrastructure offers peace of mind. Your data stays within your control, rather than being processed by a third-party service.
  • Learning Opportunity: Setting up n8n with Docker is a fantastic way to deepen your technical skills – invaluable for any tech-savvy entrepreneur.

What you'll need:

  • A server (VPS or Raspberry Pi).
  • A domain name (highly recommended for SSL).
  • Basic Linux command line familiarity.
  • Docker and Docker Compose installed.

Choosing Your Server & Getting Docker Ready

Your first decision is where n8n will live. You have a couple of excellent options:

Option 1: Virtual Private Server (VPS)

A VPS is a virtual machine running on a provider's hardware. It's affordable, reliable, and generally the easiest option for beginners. Providers like DigitalOcean, Vultr, Linode, or even OVH offer excellent value starting from around £4-£5 per month for a basic server with 1-2GB RAM – perfect for n8n. I'd recommend a server running Ubuntu 22.04 LTS.

Option 2: Raspberry Pi (and an SSD!)

For the ultra cost-conscious or those who love tinkering, a Raspberry Pi 4 Model B (4GB or 8GB RAM is ideal) is a fantastic choice. It's low-power and quiet. However, it's absolutely critical to use a fast USB 3.0 SSD (e.g., a SanDisk Extreme Portable SSD) for your operating system and n8n data, not a microSD card. MicroSD cards are prone to corruption with constant read/write cycles, which n8n will generate.

Installing Docker and Docker Compose

Once you have your server ready (either a fresh VPS or a Raspberry Pi running Raspberry Pi OS), the next step is to install Docker and Docker Compose. SSH into your server and run these commands:

# Update your systemsudo apt update && sudo apt upgrade -y# Install Docker (use the official convenience script for a quick setup, or follow official docs)curl -sSL https://get.docker.com | sh# Add your user to the docker group (so you don't need 'sudo' for docker commands)sudo usermod -aG docker $USER# Log out and back in, or run 'newgrp docker' for changes to take effectnewgrp docker# Install Docker Compose (often included with Docker Engine nowadays, but check)sudo apt install docker-compose-plugin -y# Verify installationdocker --versiondocker compose version

You should see version numbers, confirming Docker and Docker Compose are ready.

The Core n8n Docker Setup with PostgreSQL

We'll use Docker Compose to define and run our n8n services. We're going to set up n8n with a PostgreSQL database for robust, production-ready persistence, rather than the default SQLite (which is fine for testing but not recommended for long-term use).

First, create a directory for your n8n setup:

mkdir n8n-setupcd n8n-setup

Now, create a file named docker-compose.yml:

nano docker-compose.yml

Paste the following content, making sure to replace placeholder values with your own secure information:

version: '3.8'services:  n8n:    image: n8nio/n8n    restart: always    ports:      - "5678:5678" # This port will be exposed to the internet IF you don't use a reverse proxy    volumes:      - ./n8n_data:/home/node/.n8n # Persistent data for n8n config, workflows etc.    environment:      # Timezone for n8n execution      - TZ=Europe/London      # IMPORTANT: Generate a strong, unique key for encryption      - N8N_ENCRYPTION_KEY=YOUR_SUPER_SECURE_ENCRYPTION_KEY_HERE      # Database configuration      - DB_TYPE=postgresdb      - DB_POSTGRESDB_HOST=n8n_postgres      - DB_POSTGRESDB_PORT=5432      - DB_POSTGRESDB_DATABASE=n8n      - DB_POSTGRESDB_USER=n8n      - DB_POSTGRESDB_PASSWORD=YOUR_POSTGRES_PASSWORD_HERE      # For webhooks and general N8N URL, updated after reverse proxy setup      - N8N_PROTOCOL=http      - N8N_HOST=localhost      - WEBHOOK_URL=http://localhost:5678/  n8n_postgres:    image: postgres:15-alpine    restart: always    environment:      - POSTGRES_DB=n8n      - POSTGRES_USER=n8n      - POSTGRES_PASSWORD=YOUR_POSTGRES_PASSWORD_HERE    volumes:      - ./postgres_data:/var/lib/postgresql/data # Persistent data for PostgreSQL

Explanation of key variables:

  • N8N_ENCRYPTION_KEY: Absolutely critical! Generate a long, random string (e.g., using a password manager or a command like head /dev/urandom | tr -dc A-Za-z0-9_ | head -c 32 ; echo ''). This encrypts sensitive credentials in your workflows. If you lose it, you lose access to those credentials!
  • YOUR_POSTGRES_PASSWORD_HERE: Another strong, unique password for your PostgreSQL database.
  • TZ=Europe/London: Ensures n8n runs with UK time.
  • volumes: These map a directory on your server (e.g., ./n8n_data) to a directory inside the Docker container. This ensures your n8n configuration, workflows, and database data persist even if you restart or update the containers.

Save and exit (Ctrl+X, Y, Enter).

Now, bring up your n8n stack:

docker compose up -d

After a minute or two, n8n should be running. You can check its status:

docker compose ps

You should see both n8n and n8n_postgres in an 'Up' state. If you visit http://YOUR_SERVER_IP:5678 in your web browser, you should see the n8n setup screen!

Adding a Reverse Proxy & SSL (Crucial for Production)

Exposing n8n directly on port 5678 isn't ideal for production. We need a reverse proxy to handle SSL (HTTPS), custom domain names, and standard web ports (80/443). Caddy is an excellent, easy-to-configure option that automatically handles Let's Encrypt SSL certificates.

First, update your docker-compose.yml to include Caddy:

nano docker-compose.yml

Add a new service for Caddy, and adjust n8n's port mapping (we no longer need to expose 5678 directly to the host, as Caddy will handle it) and environment variables:

version: '3.8'services:  n8n:    image: n8nio/n8n    restart: always    # Remove or comment out 'ports: - "5678:5678"' here    volumes:      - ./n8n_data:/home/node/.n8n    environment:      - TZ=Europe/London      - N8N_ENCRYPTION_KEY=YOUR_SUPER_SECURE_ENCRYPTION_KEY_HERE      - DB_TYPE=postgresdb      - DB_POSTGRESDB_HOST=n8n_postgres      - DB_POSTGRESDB_PORT=5432      - DB_POSTGRESDB_DATABASE=n8n      - DB_POSTGRESDB_USER=n8n      - DB_POSTGRESDB_PASSWORD=YOUR_POSTGRES_PASSWORD_HERE      # UPDATE these for your domain      - N8N_PROTOCOL=https      - N8N_HOST=your.domain.com # Replace with your actual domain      - WEBHOOK_URL=https://your.domain.com/ # Replace with your actual domain  n8n_postgres:    image: postgres:15-alpine    restart: always    environment:      - POSTGRES_DB=n8n      - POSTGRES_USER=n8n      - POSTGRES_PASSWORD=YOUR_POSTGRES_PASSWORD_HERE    volumes:      - ./postgres_data:/var/lib/postgresql/data  caddy:    image: caddy:2.7.5-alpine    restart: always    ports:      - "80:80"      - "443:443"    volumes:      - ./Caddyfile:/etc/caddy/Caddyfile # Caddy configuration file      - ./caddy_data:/data # Persistent data for Caddy (e.g., SSL certs)

Now, create a Caddyfile in the same directory (n8n-setup):

nano Caddyfile

Add this content, replacing your.domain.com with your actual domain name:

your.domain.com {  reverse_proxy n8n:5678  # Optional: Log requests (useful for debugging)  log {    output file /data/access.log  }}

Before you restart, make sure your domain's DNS A record points to your server's IP address. This is crucial for Caddy to obtain SSL certificates.

Now, bring down the old stack and bring up the new one:

docker compose downdocker compose up -d

You should now be able to access n8n securely via https://your.domain.com! Caddy will automatically fetch and renew your Let's Encrypt SSL certificate.

Maintenance, Backups & Next Steps

You've successfully set up n8n! Now let's talk about keeping it running smoothly and securely.

Updating n8n and Docker Images

It's vital to keep your n8n instance and Docker images updated for security patches and new features. Stop your containers, pull the latest images, and bring them back up:

docker compose pulldocker compose up -d

Remember to check n8n's official changelog before major updates, especially if you have complex workflows, to anticipate any breaking changes.

Backing Up Your Data (Don't Skip This!)

Your workflows and credentials are invaluable. Regular backups are non-negotiable. You need to back up two critical directories from your server:

  • ./n8n_data: Contains n8n's configuration, custom nodes, and some settings.
  • ./postgres_data: Contains all your PostgreSQL database data (your workflows, executions, etc.).

You can use tools like rsync to copy these directories to a remote storage solution (e.g., an S3 bucket, Google Drive via rclone, or another server). For example, a simple script could look like:

#!/bin/bashBACKUP_DIR="/path/to/your/backup/location"TIMESTAMP=$(date +%Y%m%d-%H%M%S)cd /path/to/your/n8n-setup # Navigate to your n8n-setup directorydocker compose down # Stop n8n to ensure consistent backupstar -czf "$BACKUP_DIR/n8n_data_backup_$TIMESTAMP.tar.gz" n8n_datatar -czf "$BACKUP_DIR/postgres_data_backup_$TIMESTAMP.tar.gz" postgres_datadocker compose up -d # Restart n8necho "Backup completed at $TIMESTAMP"

Automate this script with a cron job to run daily or weekly.

Speaking of making life easier, if you're keen to hit the ground running with ready-made solutions, our very own n8n Starter Workflows are designed to do just that. They're plug-and-play n8n workflow templates that you can import in minutes, giving you a head start on common automation tasks (from £9).

Security Best Practices

  • Strong Passwords: For your server, n8n user, and database.
  • Firewall: Configure your server's firewall (e.g., ufw on Ubuntu) to only allow incoming connections on ports 22 (SSH), 80 (HTTP), and 443 (HTTPS).
  • Regular Updates: Keep your server's operating system updated: sudo apt update && sudo apt upgrade -y.
  • Monitor Logs: Periodically check Docker container logs (docker compose logs -f n8n and docker compose logs -f caddy) for any unusual activity.

Conclusion

Phew! You've just completed a significant step in taking control of your automation stack. Self-hosting n8n with Docker might seem daunting at first, but with this guide, you now have a robust, secure, and cost-effective setup that empowers your digital side hustle with unparalleled flexibility and privacy. From here, the world of automation is your oyster. Start building those workflows, automating those tedious tasks, and reclaiming your time!

If you hit any snags, the n8n community forum is a fantastic resource, and remember to double-check your environment variables and Caddyfile for typos. Happy automating!

Written by

Richard Tucker

View all posts →