AiratTop/n8n-self-hosted

Production-ready Docker Compose setup for a scalable and secure self-hosted n8n. Includes Caddy (auto-HTTPS), workers, backup scripts, and security best practices out of the box.

★ 12Forks 4ShellGitHub ↗Compare

Project website ↗

airathalitovairattopautomationbackupcaddydeploymentdevopsdockerdocker-composen8nn8n-automationpostgresredissefl-hostedworkflow-automation

README

n8n Self-Hosted with Docker

n8n-self-hosted

This repository provides a Docker Compose setup for running a self-hosted n8n instance with scaling capabilities.

Features

  • Works out of the box: Just configure the .env file and run the start script.
  • Scalable: Runs n8n in queue mode with separate workers, ready for high loads.
  • Handles Large Files: Configured to save binary data to the filesystem, allowing workflows to process large files without memory issues.
  • Ready-to-use Scripts: Includes simple scripts to start, restart, and update the application.
  • Long-term History: Execution history is stored for 2 months.
  • Secure: Uses the latest recommended security environment variables for n8n.
  • Private: n8n telemetry is disabled by default.
  • Full-featured: SMTP is pre-configured for password recovery and other email functions.
  • Automatic HTTPS: Uses Caddy as a reverse proxy for automatic SSL certificates.
  • Persistent Data: Data is stored in a PostgreSQL database.
  • Caching: Uses Redis for caching.

Prerequisites

  • Docker and Docker Compose installed.
  • A domain name pointed to your server's IP address.
  • A .env file with the required environment variables.

Usage

  1. Clone the repository:

    git clone https://github.com/AiratTop/n8n-self-hosted
    cd n8n-self-hosted
  2. Create the shared network: This setup uses a shared network to easily connect to external databases. If you haven't already, create the network:

    docker network create shared_network
  3. Configure the environment: Open the .env file and update the variables with your own settings. You can use my Open Source password generator to create a strong password.

  4. Start the application:

    ./start-docker.sh

    This will start all the services in detached mode and scale the n8n-worker service to 2 replicas.

  5. Restart the application:

    ./restart-docker.sh
  6. Update the application:

    ./update-docker.sh

    This will automatically create a database backup, pull the latest Docker images, and restart the application.

Backup

This project includes a script to back up the n8n database.

To create a backup, run:

./backup.sh

This will create a compressed SQL dump of your PostgreSQL database in the local_files/backups/ directory. It is recommended to run this script regularly (e.g., using a cron job).

Connecting to Other Services

This n8n setup is part of a larger ecosystem of self-hosted services that can all run on the same shared_network. This allows n8n to securely connect to them using their container names as hostnames.

See Also

Check out these pre-configured services that work out-of-the-box with this n8n instance:

Services

  • caddy: Reverse proxy
  • n8n-master: Main n8n instance
  • n8n-worker: n8n worker instances
  • n8n-psql: PostgreSQL database
  • n8n-redis: Redis cache

License

The original Docker Compose files, configuration, scripts, and documentation in this repository are licensed under the Apache License 2.0, with copyright details in NOTICE.

Docker images and third-party software referenced by this deployment template are not covered by this license. They remain subject to their respective licenses and terms.


Author

AiratTop (Airat Halitov)

Contributors

AiratTop

Issues