n8n is a powerful workflow automation tool that can be enhanced with Redis for caching and improved performance. This tutorial will guide you through setting up both services using Docker containers with proper networking configuration.
Prerequisites
Before you begin this guide, you’ll need:
- A server running Ubuntu 18.04 or later (other Linux distributions will work similarly)
- Docker installed and running on your system
- Basic familiarity with Docker commands
- Sudo privileges or root access
Step 1 — Creating a Docker Network
First, we’ll create a dedicated Docker network to enable secure communication between the Redis and n8n containers. This approach isolates our services and allows them to communicate using container names instead of IP addresses.
Create the network with the following command:
bash
docker network create n8n-network
This command creates a bridge network named n8n-network
that will allow our containers to communicate with each other while remaining isolated from other Docker containers.
Why this works: Docker networks provide DNS resolution between containers, meaning the Redis container will be accessible to n8n using the hostname redis
rather than needing to know its IP address.
Step 2 — Deploying the Redis Container
Next, we’ll start a Redis container that will serve as our caching layer for n8n. Redis will improve n8n’s performance by caching frequently accessed data.
Run the Redis container with this command:
bash
docker run -d \
--name redis \
--network n8n-network \
-p 6379:6379 \
redis
Let’s break down these options:
-d
: Runs the container in detached mode (in the background)--name redis
: Assigns the name “redis” to the container for easy reference--network n8n-network
: Connects the container to our custom network-p 6379:6379
: Maps the Redis port from the container to the host (optional for external access)
Note: The port mapping (-p 6379:6379
) is optional if you only need Redis for n8n communication, as containers on the same network can communicate directly.
Step 3 — Creating a Persistent Volume for n8n
To ensure your n8n workflows and data persist across container restarts, create a Docker volume:
bash
docker volume create n8n_data
This volume will store all n8n configuration files, workflows, and user data in a location that survives container lifecycle changes.
Step 4 — Deploying the n8n Container
Now we’ll start the n8n container with Redis caching enabled and proper configuration:
bash
docker run -d --rm \
--name n8n \
--network n8n-network \
-p 5678:5678 \
-e GENERIC_TIMEZONE="Australia/Brisbane" \
-e TZ="Australia/Brisbane" \
-e N8N_CACHE_ENABLED="true" \
-e N8N_HOST="n8.yourdomain.com" \
-e WEBHOOK_URL="https://n8.yourdomain.com" \
-e N8N_CACHE_REDIS_PORT="6379" \
-e N8N_CACHE_REDIS_HOST="redis" \
-v n8n_data:/home/node/.n8n \
docker.n8n.io/n8nio/n8n
Here’s what each environment variable does:
GENERIC_TIMEZONE
andTZ
: Set the timezone for proper scheduling and loggingN8N_CACHE_ENABLED="true"
: Enables Redis caching functionalityN8N_HOST
: Sets the hostname for n8n (replace with your domain)WEBHOOK_URL
: Configures the webhook URL for external integrationsN8N_CACHE_REDIS_HOST="redis"
: Points to our Redis container using the network hostnameN8N_CACHE_REDIS_PORT="6379"
: Specifies the Redis port
Important: Replace n8.yourdomain.com
with your actual domain name or use localhost
for local development.
Step 5 — Configuring Redis Access in n8n Workflows
When creating Redis nodes within your n8n workflows, use these connection settings:
- Host:
redis
(this uses the container name on our Docker network) - Port:
6379
(standard Redis port) - Username: Leave blank (Redis default configuration)
- Password: Leave blank (Redis default configuration)
- Database Index: Set according to your requirements (typically 0-15)
Why this works: Since both containers are on the same Docker network, n8n can reach Redis using the container name redis
as the hostname, which Docker’s internal DNS resolves automatically.
Step 6 — Verifying the Installation
To confirm everything is working correctly:
- Check that both containers are running:
bash
docker ps
- Access n8n by navigating to
http://your-server-ip:5678
in your web browser - Test Redis connectivity by creating a simple workflow with a Redis node using the connection settings from Step 5
Conclusion
You now have a fully functional n8n installation with Redis caching. This setup provides:
- Improved Performance: Redis caching reduces database load and speeds up workflow execution
- Persistent Storage: Your workflows and data are preserved across container restarts
- Network Isolation: Services communicate securely within their dedicated network
- Scalability: This foundation can be extended with additional services as needed
For production deployments, consider implementing additional security measures such as Redis authentication, SSL/TLS encryption, and proper firewall configuration.
Leave a Reply