DEV Community

Cover image for How to Set Up n8n on DigitalOcean with Docker and Caddy
Nasrul Hazim Bin Mohamad
Nasrul Hazim Bin Mohamad

Posted on

How to Set Up n8n on DigitalOcean with Docker and Caddy

Introduction
Automating workflows has become an essential part of modern businesses, and n8n is a powerful, self-hostable automation tool that simplifies the process. In this guide, we'll walk you through setting up n8n on a DigitalOcean Droplet using Docker and Caddy, ensuring a secure and efficient deployment.

Prerequisites
Before we begin, make sure you have the following:

  • A DigitalOcean account
  • Basic knowledge of Linux commands
  • Domain and subdomain ready for your setup

Step 1: Create a DigitalOcean Droplet

  1. Log in to your DigitalOcean account.
  2. Select a project or create a new one.
  3. Navigate to Manage > Droplets > Create Droplet.
  4. Choose the Docker image from the Marketplace tab.
  5. Select a plan based on your resource requirements (Basic Shared CPU plan is usually sufficient).
  6. Finalise your Droplet setup and note the IP address.

Step 2: Secure Your Droplet
Log in to your new Droplet via SSH:

ssh root@<Your-Droplet-IP>
Enter fullscreen mode Exit fullscreen mode

Create a new user for managing n8n:

adduser <USERNAME>
usermod -aG sudo <USERNAME>
Enter fullscreen mode Exit fullscreen mode

Log out and log back in as the new user:

ssh <USERNAME>@<Your-Droplet-IP>
Enter fullscreen mode Exit fullscreen mode

Step 3: Clone the n8n Docker Repository
Clone the n8n Docker setup with Caddy:

git clone https://github.com/n8n-io/n8n-docker-caddy.git
cd n8n-docker-caddy
Enter fullscreen mode Exit fullscreen mode

Step 4: Create Docker Volumes
Set up persistent storage for Caddy and n8n:

sudo docker volume create caddy_data
sudo docker volume create n8n_data
Enter fullscreen mode Exit fullscreen mode

Step 5: Configure Firewall
Allow HTTP and HTTPS traffic:

sudo ufw allow 80
sudo ufw allow 443
Enter fullscreen mode Exit fullscreen mode

Step 6: Update Environment Variables
Create or update your .env file:

DATA_FOLDER=/home/<USERNAME>/n8n-docker-caddy
SUBDOMAIN=n8n
DOMAIN=yourdomain.com
GENERIC_TIMEZONE="Asia/Kuala_Lumpur"
Enter fullscreen mode Exit fullscreen mode

Replace <USERNAME> and yourdomain.com with your user and domain details.

Step 7: Update Caddyfile
Open caddy_config/Caddyfile and add your subdomain configuration:

n8n.yourdomain.com {
    reverse_proxy n8n:5678 {
      flush_interval -1
    }
}
Enter fullscreen mode Exit fullscreen mode

Save and close the file.

Step 8: Start Docker Containers
Bring up the containers:

sudo docker-compose up -d
Enter fullscreen mode Exit fullscreen mode

Step 9: Access n8n
Open your browser and navigate to:

https://n8n.yourdomain.com
Enter fullscreen mode Exit fullscreen mode

You should now see the n8n interface.

Conclusion
Congratulations! You've successfully deployed n8n on DigitalOcean using Docker and Caddy. With this setup, you can now start building and managing your automation workflows efficiently.

For more details and troubleshooting, refer to the n8n documentation.


Photo by Codioful (Formerly Gradienta) on Unsplash

Top comments (0)