How to install n8n in Linux using Docker-Compose

Introduction

n8n.io is your secret weapon for workflow automation! It’s a user-friendly platform that lets you automate tasks across different tools and platforms you already use, saving you time and effort.

Here’s what makes n8n.io so awesome:

  • Effortless Automation: No coding needed! n8n.io’s drag-and-drop interface lets anyone build automated workflows, even beginners.
  • Mega-Flexible: With a huge variety of pre-built “nodes,” you can connect any tools you need to create custom workflows for your specific tasks.
  • Plays Well with Others: Integrate n8n.io with all your favorite tools, finally breaking down those information silos!
  • Fort Knox for Your Data: Security is a top priority, so n8n.io keeps your data safe and sound.
  • Built to Scale: Whether you’re a startup or a giant corporation, n8n.io scales with your needs to keep your workflows efficient.

Supercharge Your Processes with Real-World Examples:

  • Marketing Magic: Automatically schedule social media posts, send personalized emails, and track campaign results – all on autopilot!
  • HR Hero: Streamline employee onboarding, automate leave requests, and free up HR for more strategic work.
  • E-commerce Edge: Boost your online store with automated order confirmations, inventory updates, and customer feedback requests.
  • Finance Force: Simplify tasks like transaction categorization, invoice processing, and financial reporting for a smoother financial flow.
  • Customer Champion: Deliver exceptional customer service with automated ticket assignments, response emails, and feedback tracking.
  • Data Dream Team: Synchronize data across different platforms to eliminate redundancy and errors, keeping your information clean and organized.

Not Sure if n8n.io is Right for You?

Here’s a quick breakdown of the pros and cons:

Pros:

  • Easy to use, even for beginners
  • Ultra-flexible with tons of pre-built options
  • Integrates with all your favorite tools
  • Keeps your data safe and secure
  • Grows with your business

Cons:

  • There’s a bit of a learning curve for new users
  • Might not have all the super advanced features for complex workflows
  • Needs a stable internet connection to run smoothly
  • Regular updates might require adjustments to your workflows

The Takeaway:

n8n.io is a powerful tool that can transform the way you work. If you’re looking to automate tasks, improve efficiency, and boost productivity, n8n.io is definitely worth checking out!https://n8n.io/

Install n8n with Docker-Compose

This guide walks you through installing n8n with Docker-compose, leveraging the efficiency of containerization.

Prerequisites:

  • Docker installed and running on your system.
  • Docker-compose installed and configured.
  • Ubuntu Server (Latest version) with minimum 2 CPU Core and 4GB Ram.
  • One “Fully Qualified Domain Name”

Let’s Dive In!

Docker and Docker-Compose Installation with script

## paste this below script in terminal
apt update && 
apt upgrade -y &&
curl -fsSL https://get.docker.com -o get-docker.sh &&
sudo sh get-docker.sh &&
curl -SL https://github.com/docker/compose/releases/download/v2.13.0/docker-compose-linux-x86_64 -o /usr/local/bin/docker-compose &&
chmod +x /usr/local/bin/docker-compose &&
apt-get install docker-compose-plugin

Clone Git Repository:

  1. Access the n8n project on GitHub Repository
  2. Navigate to the docker/compose directory within the repository.
  3. Locate the withPostgresAndWorker folder. This folder contains the configuration file specifically designed for deploying n8n with Docker-Compose, alongside a worker container for enhanced performance.
  4. Open “docker-compose.yml” delete all existing code and paste the below code.
  5. Configure Environments Variable
## Clone the n8n repository
git clone https://github.com/n8n-io/n8n.git

## Navigate the "withPostgresAndWorker" folder
cd n8n/docker/compose/withPostgresAndWorker

## edit the docker-compose.yml file
nano docker-compose.yml

##Replace all existing code with below code
version: '3.8'

volumes:
  db_storage:
  n8n_storage:
  redis_storage:

x-shared: &shared
  restart: always
  image: docker.n8n.io/n8nio/n8n
  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}
    - EXECUTIONS_MODE=queue
    - QUEUE_BULL_REDIS_HOST=redis
    - QUEUE_HEALTH_CHECK_ACTIVE=true
    - N8N_ENCRYPTION_KEY=${N8N_ENCRYPTION_KEY}
    - WEBHOOK_URL=${WEBHOOK_URL}
  links:
    - postgres
    - redis
  volumes:
    - n8n_storage:/home/node/.n8n
  depends_on:
    redis:
      condition: service_healthy
    postgres:
      condition: service_healthy

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

  redis:
    image: redis:6-alpine
    restart: always
    volumes:
      - redis_storage:/data
    healthcheck:
      test: ['CMD', 'redis-cli', 'ping']
      interval: 5s
      timeout: 5s
      retries: 10

  n8n:
    <<: *shared
    ports:
      - 5678:5678

  n8n-worker:
    <<: *shared
    command: worker
    depends_on:
      - n8n

Press “Ctrl + X”, press “Y” and then press “Enter” key

Inside the .env file, define the following environment variables, replacing placeholders with your desired values:

  • POSTGRES_DB: Name of your PostgreSQL database (e.g., my_n8n_database).
  • POSTGRES_NON_ROOT_USER: Username for accessing the database (e.g., n8n_user).
  • POSTGRES_NON_ROOT_PASSWORD: Password for the database user.
  • WEBHOOK_URL: Your domain name or Your Server IP(https://your-domain-name.com)
  • N8N_ENCRYPTION_KEY: A strong encryption key for n8n.
## Paste this below command in terminal for generating "N8N_ENCRYPTION_KEY"
cat /dev/urandom | tr -dc 'a-zA-Z0-9' | fold -w 24 | head -n 1



########Example .env code########

POSTGRES_USER=root
POSTGRES_PASSWORD=dfjk395ASdkOwL45msk
POSTGRES_DB=n8n
POSTGRES_NON_ROOT_USER=n8n_user
POSTGRES_NON_ROOT_PASSWORD=395ASdkOr8jKgBnv
N8N_ENCRYPTION_KEY=abJkwiQPfg1Gr5Kd7890ABCdefG01xcdsk3iKefdjk3
WEBHOOK_URL=https://n8n8.gleeze.com/

#################################

Press “Ctrl + X”, press “Y” and then press “Enter” key.

Optional: Environment Variable Customization

n8n offers additional environment variables for fine-tuning its behavior. Explore the official documentation for a comprehensive list:

Start the n8n Services:

Execute the following command in your terminal to initiate the deployment using Docker-compose:

docker-compose up -d

The -d flag instructs Docker-compose to run the containers in detached mode, allowing you to continue using your terminal for other tasks.

Verify Installation:

After running the previous command, n8n, PostgreSQL (the database), and the worker container will launch in the background.

Check if the containers are running properly using the following command:

docker-compose ps

This will display the status of all containers associated with the docker-compose.yml file. Ensure the containers are listed as “Up and Running.”

Accessing Your n8n Instance:

By default, n8n is accessible through your web browser at http://localhost:5678. You’ll encounter the n8n setup wizard, guiding you through the initial configuration steps.

Key Considerations:

  • Port Mapping: The default port for n8n is 5678. If this port conflicts with another application, modify the ports section within the docker-compose.yml file to specify a different port.
  • Persistent Data: The data directory for n8n is not persisted by default within Docker containers. To ensure your workflows and data remain intact after container restarts, consider mounting a volume on the host system. Refer to the Docker documentation for volume mounting instructions

Securing Your Website with Nginx Proxy Manager

Nginx Proxy Manager is a user-friendly tool that lets you manage SSL certificates and secure your website traffic. For installation of please follow this blog-post

Access the Nginx Proxy Manager Web-UI

  • Open your web browser: Navigate to the IP address of your EC2 instance followed by :81. This will open the Nginx Proxy Manager web interface.
  • Log in: Use the email admin@example.com and the password is changeme

Create a Proxy Host for Your WordPress Website

  • Click on “Hosts” in the navigation menu.
  • Click on “Add Proxy Host.”
  • Enter the following information in the respective fields:
    • Host Name: The domain name or subdomain you want your website to be accessible through.
    • Scheme: Choose “HTTP.”
    • Forward Hostname / IP : Paste your “Server IP” or “n8n Container Gateway IP” ( using this command: “docker inspect container-id
    • Forward Ports; 5678
  • Click on “Save.”

Request an SSL Certificate

  • Click on “SSL” in the navigation menu.
  • Click on “Let’s Encrypt” tab.
  • Click on “Request SSL Certificate.”
  • Select the domain name you created the proxy host for.
  • Click on “Request.”

Install the SSL Certificate

  • Wait for the certificate request to be processed. This might take a few minutes.
  • Once the certificate is issued,

Congratulations! Your website is now accessible securely through HTTPS with an SSL certificate issued by Let’s Encrypt.

Watch Video Tutorial:

Confused about setting up your own n8n? Ditch the dry guides and watch my video tutorial

  • Clear, concise instructions in Urdu/Hindi with 80 different languages translation
  • Visual demonstration makes every step crystal clear.
  • Time-saving guide gets you up and running fast.
kash

Recent Posts

How to Install OpenProject: A Step-by-Step Guide for Beginners

Introduction OpenProject is a project management tool designed to help teams organize, collaborate, and track…

4 weeks ago

Part 2: Jitsi Meet Host Authentication & JWT Token Configuration

Hey there! Welcome back to the website, and today we're diving deeper into Jitsi Meet.…

6 months ago

Self-Hosted Chat: Set Up Your Own Mattermost Server with Ease

Introduction Boost your team's collaboration and productivity with Mattermost, a secure and versatile communication platform.…

8 months ago

How to Install Nextcloud All-in-One on Linux

What is Nextcloud? Nextcloud is an awesome open-source platform that gives you exactly that. Think…

10 months ago

How to install Chatwoot on Ubuntu using Script

Introduction Taming the Inbox Beast: What is Chatwoot and How Can it Save You From…

11 months ago

Complete Guide to WordPress installation on AWS with Docker-Compose

What is WordPress? Imagine a blank canvas, ready for you to paint your masterpiece. That's…

12 months ago