Workflow Automation with n8n | Installation

2 min read

What is n8n and how does it look?

Short answer IFTTT-like self-hosted alternative, details? Check https://n8n.io/

How to install?

Please note that I am hosting with Raspberry Pi hence the easier to maintenance and configure for me is through docker which mean the image used is arm-based. This tutorial expects that you knew docker and docker-compose already. The database I am using is PostgreSQL 11 feel free to change if you prefer MySQL. Lastly, please FIX the path, CHANGE the username and use a STRONG password.

Use docker-compose

First create file .env and paste below:

POSTGRES_USER=pgroot
POSTGRES_PASSWORD=pgroot-password
POSTGRES_DB=n8n

POSTGRES_NON_ROOT_USER=n8n
POSTGRES_NON_ROOT_PASSWORD=n8n-password

N8N_BASIC_AUTH_USER=user
N8N_BASIC_AUTH_PASSWORD=password

# The top level domain to serve from
DOMAIN_NAME=example.com

# The subdomain to serve from
SUBDOMAIN=workflow

Then create file docker-compose.yml and copy and paste below:

version: '3.1'

services:

  postgres:
    image: postgres:11
    restart: always
    environment:
      - POSTGRES_USER
      - POSTGRES_PASSWORD
      - POSTGRES_DB
      - POSTGRES_NON_ROOT_USER
      - POSTGRES_NON_ROOT_PASSWORD
    volumes:
      - /path/to/.config/appdata/n8n/init-data.sh:/docker-entrypoint-initdb.d/init-data.sh
      - /path/to/.config/appdata/n8n/postgresql:/var/lib/postgresql/data

  n8n:
    image: n8nio/n8n:0.96.0-rpi
    restart: always
    environment:
      - DB_TYPE=postgresdb
      - DB_POSTGRESDB_HOST=postgres
      - DB_POSTGRESDB_PORT=5432
      - DB_POSTGRESDB_DATABASE=${POSTGRES_DB}
      - DB_POSTGRESDB_USER=${POSTGRES_NON_ROOT_USER}
      - DB_POSTGRESDB_PASSWORD=${POSTGRES_NON_ROOT_PASSWORD}
      - N8N_BASIC_AUTH_ACTIVE=true
      - N8N_BASIC_AUTH_USER
      - N8N_BASIC_AUTH_PASSWORD
      - N8N_HOST=${SUBDOMAIN}.${DOMAIN_NAME}
      - N8N_PORT=5678
      - N8N_PROTOCOL=https
      - NODE_ENV=production
      - WEBHOOK_TUNNEL_URL=https://${SUBDOMAIN}.${DOMAIN_NAME}/
      - VUE_APP_URL_BASE_API=https://${SUBDOMAIN}.${DOMAIN_NAME}/
      - GENERIC_TIMEZONE=Asia/Singapore
      - TZ=Asia/Singapore
    ports:
      - 5678:5678
    links:
      - postgres
    volumes:
      - /path/to/.config/appdata/n8n/.n8n:/home/node/.n8n
    # Wait 5 seconds to start n8n to make sure that PostgreSQL is ready
    # when n8n tries to connect to it
    command: /bin/sh -c "sleep 5; n8n start"

and as usual run docker-compose command

docker-compose up -d