3.7 KiB
n8n Self-Hosted with Docker
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
.envfile and run the start script. - Scalable: Runs n8n in
queuemode 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
.envfile with the required environment variables.
Usage
-
Clone the repository:
git clone https://github.com/AiratTop/n8n-self-hosted cd n8n-self-hosted -
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 -
Configure the environment: Open the
.envfile and update the variables with your own settings. -
Start the application:
./start-docker.shThis will start all the services in detached mode and scale the
n8n-workerservice to 2 replicas. -
Restart the application:
./restart-docker.sh -
Update the application:
./update-docker.shThis 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 External Databases
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.
Check out these pre-configured databases that work out-of-the-box with this n8n instance:
- postgresql-self-hosted: A simple and robust PostgreSQL setup.
- mysql-self-hosted: A self-hosted MySQL instance.
- clickhouse-self-hosted: High-performance columnar database for analytics.
- qdrant-self-hosted: A vector database for AI applications.
Services
caddy: Reverse proxyn8n-master: Main n8n instancen8n-worker: n8n worker instancesn8n-psql: PostgreSQL databasen8n-redis: Redis cache
License
This project is licensed under the MIT License - see the LICENSE file for details.
Author
Airat Halitov
- Website: airat.top
- GitHub: @AiratTop
- Repository: n8n-self-hosted