Home » Blog » How to self-host n8n using Docker

How to self-host n8n using Docker

n8n is a popular and open-source workflow automation tool, which you can self-host on a Hetzner Cloud server using Docker Compose and Caddy as a reverse proxy. This detailed tutorial ensures a smooth setup while highlighting best practices for security and maintenance.

What you need

Before starting, ensure you meet these requirements:

  • Docker CE installed on your server (View guide)
  • A domain name pointed to your server’s IP address

Technologies used in this guide

  • Hetzner Cloud Server (image: Docker CE pre-installed)
  • Docker & Docker Compose for containerized deployment
  • Caddy as the reverse proxy
  • n8n (latest stable version)

Note: We’ll use Hetzner Cloud as our hosting provider, but you can use any other provider as well, that comes with a pre-installed version of Docker CE or where you can self install Docker CE.

Deploy n8n using docker-compose

Step 1: Prepare the server

In this step, you will:

  1. Update the system packages.
  2. Install the Docker Compose plugin.
  3. Clone the n8n setup repository.
  4. Create required Docker volumes.

Run the following commands on your server via SSH:

Bash
# Update the system packages
apt update && apt -y upgrade

# Install Docker Compose plugin
apt install docker-compose-plugin

# Clone the n8n setup repository
git clone https://github.com/n8n-io/n8n-docker-caddy.git
cd n8n-docker-caddy

# Create necessary Docker volumes
docker volume create caddy_data
docker volume create n8n_data

Step 2: Open required ports

Configure your server’s firewall:

Bash
sudo ufw allow 80  # Allow HTTP traffic
sudo ufw allow 443 # Allow HTTPS traffic

Step 3: Set Up DNS for Your Subdomain

Set up DNS records for your domain with your registrar:

  • Type: A
  • Host: n8n (or your preferred subdomain)
  • Value: Your server’s public IP address
  • TTL: 3600 (or default)

Wait for DNS propagation to complete, which may take a few minutes.

Step 4: Update Environment Variables

Edit the .env file:

Bash
nano .env

Update the following variables:

  • N8N_HOST – e.g., n8n.example.com
  • N8N_PROTOCOL – Use https
  • N8N_PORT – Default is 5678
  • N8N_ENCRYPTION_KEY – Set a secure encryption key
  • DOMAIN_NAME – Your domain (e.g., example.com)
  • SUBDOMAIN – Subdomain for n8n (e.g., n8n)
  • N8N_BASIC_AUTH_USER – Admin username for basic auth
  • N8N_BASIC_AUTH_PASSWORD – Strong admin password

Step 5: Set Up Caddy as a reverse proxy

Edit the Caddy configuration file:

Bash
nano caddy_config/Caddyfile

Replace the domain placeholder with your subdomain:

Bash
n8n.example.com {
    reverse_proxy n8n:5678 {
        flush_interval -1
    }
}

Step 6: Launch n8n

Start n8n and its dependencies:

Bash
docker compose up -d

Verify that the services are running:

Bash
docker ps

Visit your domain in a web browser to confirm that n8n is accessible.

That’s it, you’re done.


Maintenance Commands

Stop n8n

Bash
docker compose stop

Update n8n

Bash
# Pull the latest image
docker compose pull

# Restart the updated containers
docker compose down && docker compose up -d

Troubleshooting

Common Issues

  1. Cannot access the n8n interface:
    • Verify DNS records and propagation.
    • Ensure the server firewall allows ports 80 and 443.
    • Confirm Docker containers are running.
  2. Docker Compose errors:
    • Check the .env file for misconfigurations.
    • Restart the Docker service: sudo systemctl restart docker.
    • Inspect container logs with docker logs <container_name>.
  3. SSL/TLS certificate errors:
    • Verify Caddy’s configuration file.
    • Check DNS settings for accuracy.
    • Ensure ports 80 and 443 are open.

Security Best Practices

  1. Use strong, unique passwords for n8n access.
  2. Regularly update Docker, n8n, and server packages.
  3. Enable automated backups to prevent data loss.
  4. Monitor server resources to detect anomalies.
  5. Use SSH key authentication instead of password-based SSH login.

FAQ

What is n8n?

n8n is an open-source workflow automation tool that allows you to connect various applications and automate repetitive tasks. It supports integrations with popular apps and services, enabling users to create complex workflows with little or no code.

Is n8n free to use?

Yes, n8n is open-source and free to self-host. There is also a cloud-hosted version with subscription plans for those who prefer a managed solution.

What are the system requirements for self-hosting n8n?

Minimum requirements for running n8n:
2GB RAM
1 CPU core
20GB storage
Docker or Node.js environment
PostgreSQL or SQLite database

Can I integrate n8n with other tools and apps?

Yes, n8n supports numerous integrations with third-party tools and apps. You can connect n8n to various services like Slack, Google Sheets, GitHub, and more, using built-in nodes or custom integrations.

How secure is n8n for handling sensitive data?

n8n provides options for secure data handling, including environment variables for storing sensitive information and support for HTTPS with SSL certificates. For additional security, it is recommended to use secure networking practices and keep n8n updated.

Do I need coding skills to use n8n?

No, n8n is designed to be user-friendly, allowing you to create workflows with a visual editor. However, basic knowledge of programming or APIs can help if you want to create custom nodes or perform advanced integrations.

How can I set up SSL for n8n?

You can configure SSL for n8n by setting up an SSL certificate in your environment, using Let’s Encrypt or another provider. When using Docker, make sure to include the certificate configuration in your docker-compose.yml file and specify your domain and SSL email in the .env file.

Comments

Leave a Reply

Your email address will not be published. Required fields are marked *