How to install n8n with docker

n8n https://n8n.io/

In this guide we will use the docker-compose.yml example file from here:

Steps to install:

1. git clone https://github.com/n8n-io/n8n-hosting.git
2. cd n8n-hosting/docker-compose/withPostgres
3. nano .env
- add N8N_SECURE_COOKIE=false if you need it
5. nano docker-compose.yml
- add N8N_SECURE_COOKIE=${N8N_SECURE_COOKIE} if you need it
7.  sudo docker compose up -d

The modified .env and compose files are below.
I had to add the N8N_SECURE_COOKIE=false because i’m not useing localhost and didn’t create a certificate for this example.

After installing you can access the n8n web ui at
http://localhost:5678 or instead of localhost use your ip of the docker machine

Installation guide in video format

# Basic settings
N8N_BASIC_AUTH_ACTIVE=false
N8N_HOST=localhost
N8N_PORT=5678
N8N_PROTOCOL=http

# Security
N8N_SECURE_COOKIE=false

POSTGRES_USER=changeUser
POSTGRES_PASSWORD=changePassword
POSTGRES_DB=n8n

POSTGRES_NON_ROOT_USER=changeUser
POSTGRES_NON_ROOT_PASSWORD=changePassword
version: '3.8'

volumes:
  db_storage:
  n8n_storage:

services:
  postgres:
    image: postgres:16
    restart: always
    environment:
      - POSTGRES_USER
      - POSTGRES_PASSWORD
      - POSTGRES_DB
      - POSTGRES_NON_ROOT_USER
      - POSTGRES_NON_ROOT_PASSWORD
    volumes:
      - db_storage:/var/lib/postgresql/data
      - ./init-data.sh:/docker-entrypoint-initdb.d/init-data.sh
    healthcheck:
      test: ['CMD-SHELL', 'pg_isready -h localhost -U ${POSTGRES_USER} -d ${POSTGRES_DB}']
      interval: 5s
      timeout: 5s
      retries: 10

  n8n:
    image: docker.n8n.io/n8nio/n8n
    restart: always
    environment:
      - N8N_SECURE_COOKIE=${N8N_SECURE_COOKIE}
      - 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}
    ports:
      - 5678:5678
    links:
      - postgres
    volumes:
      - n8n_storage:/home/node/.n8n
    depends_on:
      postgres:

If you want to use cheerio in code node you can

mkdir -p ~/.n8n/modules
cd ~/.n8n/modules
npm install cheerio

modified docker compose below by adding

  • NODE_FUNCTION_ALLOW_EXTERNAL=cheerio
  • and also the volume
    • n8n_modules:/home/node/.n8n/node_modules

version: '3.8'

volumes:
  db_storage:
  n8n_storage:
  n8n_modules:

services:
  postgres:
    image: postgres:16
    restart: always
    environment:
      - POSTGRES_USER
      - POSTGRES_PASSWORD
      - POSTGRES_DB
      - POSTGRES_NON_ROOT_USER
      - POSTGRES_NON_ROOT_PASSWORD
    volumes:
      - db_storage:/var/lib/postgresql/data
      - ./init-data.sh:/docker-entrypoint-initdb.d/init-data.sh
    healthcheck:
      test: ['CMD-SHELL', 'pg_isready -h localhost -U ${POSTGRES_USER} -d ${POSTGRES_DB}']
      interval: 5s
      timeout: 5s
      retries: 10

  n8n:
    image: docker.n8n.io/n8nio/n8n
    restart: always
    environment:
      - N8N_SECURE_COOKIE=${N8N_SECURE_COOKIE}
      - 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}
      - NODE_FUNCTION_ALLOW_EXTERNAL=cheerio
    ports:
      - 5678:5678
    links:
      - postgres
    volumes:
      - n8n_storage:/home/node/.n8n
      - n8n_modules:/home/node/.n8n/node_modules

    depends_on:
      postgres:
        condition: service_healthy