Automation

How to Set Up N8N Self-Hosted with Docker

Learn step-by-step how to set up a self-hosted N8N instance using Docker for workflow automation.

5 min read

Learn step-by-step how to turn your self-hosted automation dreams into a reality by deploying an N8N instance using Docker or setting it up in the cloud. This guide covers prerequisites, setup details for both Digital Ocean and a local Docker Compose environment, along with configuration tips to ensure a secure and functional instance.

Prerequisites for Setting Up N8N Self-Hosted

Before beginning, make sure you have the following ready:

prerequisites

  • A domain name (e.g., using DuckDNS or a purchased domain) is required for SSL encryption.
  • Docker and Docker Compose properly installed on your system.
  • Basic terminal knowledge and configured SSH access for secure connections to your server.

Step-by-Step Guide to Self-Host N8N on Digital Ocean

Follow these steps to deploy an N8N instance on Digital Ocean using their marketplace droplet creation tool.

steps

  1. Sign up for Digital Ocean
    Create an account on Digital Ocean (new accounts come with a free $200 trial credit). Navigate to the Digital Ocean Marketplace and find the pre-configured N8N droplet.

  2. Create a Droplet
    Select the N8N droplet from the marketplace, choose a region, and configure hardware specifications. A basic shared CPU with minimal resources is sufficient for most initial setups.

  3. Set Up Authentication
    Choose SSH key-based authentication for secure access to the droplet. Generate and upload the public SSH key if needed.

  4. Point Your Domain to the Droplet
    Configure an A record in your domain's DNS settings to point to your droplet's public IP address.

    bash
    # Example of pinging your domain to check DNS propagation
    ping example.com
  5. Run the Setup Script
    SSH into your droplet:

bash
   ssh root@<your-droplet-IP>
   # Example: ssh root@123.45.67.89

The setup script will initiate automatically. Provide:

  • A fully qualified domain name for your N8N instance.
  • An email for setting up a free SSL from Let's Encrypt.
  1. Confirm your Installation
    Once the setup finishes, access your N8N instance using your chosen domain (e.g., https://n8n.example.com), and proceed with creating a new owner account.

Configuring N8N Locally with Docker Compose

You can also run N8N locally using Docker Compose. This method is cost-efficient and ideal for personal use.

steps

  1. Create a Project Directory
    Set up a new directory on your local machine.

    bash
    mkdir n8n-docker-setup
    cd n8n-docker-setup
  2. Create a docker-compose.yml File
    Create and edit the docker-compose.yml file.

    yaml
    version: "3"
    services:
      postgres:
        image: postgres:13
        restart: always
        environment:
          POSTGRES_USER: n8n
          POSTGRES_PASSWORD: n8npassword
          POSTGRES_DB: n8n
        ports:
          - "5432:5432"
        volumes:
          - postgres-data:/var/lib/postgresql/data
      n8n:
        image: n8nio/n8n
        restart: always
        ports:
          - "5678:5678"
        environment:
          DB_TYPE: postgresdb
          DB_POSTGRESDB_HOST: postgres
          DB_POSTGRESDB_PORT: 5432
          DB_POSTGRESDB_USERNAME: n8n
          DB_POSTGRESDB_PASSWORD: n8npassword
          DB_POSTGRESDB_DATABASE: n8n
          N8N_BASIC_AUTH_ACTIVE: "false"
          N8N_HOST: "localhost" # Local testing
        volumes:
          - n8n-data:/home/node/.n8n
    volumes:
      n8n-data:
      postgres-data:
  3. Run the Containers
    Start the environment using Docker Compose.

bash
   docker-compose up -d
  1. Access N8N Locally
    Visit http://localhost:5678 in your browser to complete setup and create an owner account.

Key Considerations in N8N Configuration

Verifying Your N8N Instance Deployment

Make sure your deployment works as intended by following these steps:

steps

  1. Check DNS Propagation
    Confirm your domain points to the correct droplet IP using a ping command.
bash
   ping example.com
   # Ensure the IP matches your droplet's IP
  1. Access Your Instance
    Use your browser to visit:

    • https://n8n.example.com (Digital Ocean setup)
    • http://localhost:5678 (Local Docker setup)
  2. Test Workflows
    Create and run a basic workflow to ensure N8N operates as expected. For instance, set up a trigger node and connect it to a simple email or schedule-based automation.

Takeaway

Self-hosting N8N offers robust automation without data privacy concerns. This guide walks you through deploying N8N on Digital Ocean or locally via Docker Compose. Remember:

  • Digital Ocean gives your instance global availability with SSL.
  • A local Docker setup enables cost-free testing and small-scale operation.

Use this foundation to start building powerful automated workflows tailored to your needs.

FAQ

How much does it cost to self-host N8N on Digital Ocean?

Starting with the smallest droplet costs around $5 per month. However, Digital Ocean offers $200 in free credits for new users, which can help you test the setup without upfront fees.

Can I update my self-hosted N8N instance later?

Yes! If you use Docker Compose, simply pull the latest N8N Docker image and restart your containers. On Digital Ocean, newer images can be deployed, but you must ensure your data (e.g., workflows) are backed up.

How do I set up SSL for a local N8N instance?

For a local setup, you’ll need to configure a reverse proxy (e.g., Nginx) and use Let's Encrypt or a paid SSL provider to secure connections. This guide covers SSL for cloud-hosted instances but not for local setups.

Is it safe to disable N8N_SECURE_COOKIES for local testing?

Yes, for local environments without HTTPS, disabling secure cookies allows N8N to operate correctly. However, it must not be disabled in production to avoid compromising security.