Deploying n8n with Docker Compose โ A Complete Guide
n8n (pronounced "n-eight-n") is an open-source workflow automation tool that helps you connect APIs, databases, and internal tools to automate tasks โ without writing complex code. In this guide, weโll walk through how to deploy n8n
using Docker Compose.
๐ Why Use Docker Compose?
Docker Compose allows you to define and run multi-container applications. With n8n, Compose makes it easy to set up: - Persistent storage - Environment variables - Auto-starting the service - Networking with other services (e.g., PostgreSQL, Redis)
๐งฐ Prerequisites
- Docker installed: Install Docker
- Docker Compose installed: Install Compose
- A basic understanding of YAML and Docker commands
๐ Folder Structure
Weโll use the following structure:
n8n-docker/
โโโ docker-compose.yml
โโโ .env
โ๏ธ .env File
Create a .env
file to store environment variables:
# Basic
N8N_BASIC_AUTH_ACTIVE=true
N8N_BASIC_AUTH_USER=admin
N8N_BASIC_AUTH_PASSWORD=securepassword
# External Access
N8N_HOST=localhost
N8N_PORT=5678
# Timezone
GENERIC_TIMEZONE=Asia/Kolkata
# Execution Mode
N8N_EXECUTIONS_MODE=queue
โ๏ธ docker-compose.yml
version: "3.8"
services:
n8n:
image: n8nio/n8n:latest
restart: always
ports:
- "5678:5678"
environment:
- N8N_BASIC_AUTH_ACTIVE=${N8N_BASIC_AUTH_ACTIVE}
- N8N_BASIC_AUTH_USER=${N8N_BASIC_AUTH_USER}
- N8N_BASIC_AUTH_PASSWORD=${N8N_BASIC_AUTH_PASSWORD}
- N8N_HOST=${N8N_HOST}
- N8N_PORT=${N8N_PORT}
- GENERIC_TIMEZONE=${GENERIC_TIMEZONE}
- N8N_EXECUTIONS_MODE=${N8N_EXECUTIONS_MODE}
volumes:
- ./n8n_data:/home/node/.n8n
โถ๏ธ Starting the Service
docker-compose up -d
- The first time it may take a while to pull the Docker image.
- Access your instance at: http://localhost:5678
๐ Access & Authentication
Youโve enabled basic auth in the .env
file, so use the credentials:
Username: admin
Password: securepassword
๐พ Persistent Data
The volume ./n8n_data:/home/node/.n8n
ensures that your workflows, credentials, and settings are retained even if the container is removed.
๐ง Tips & Extras
- You can use a reverse proxy like NGINX to expose it securely via HTTPS.
- To use external databases like PostgreSQL or Redis, just add them to the Compose file.
- Back up your volume regularly to avoid data loss.
๐งน Stopping and Removing
docker-compose down
Add -v
to remove volumes if needed:
docker-compose down -v
๐ References
Written by Santhosh Murugesan โ Simplifying automation one workflow at a time.
Note
- Based on the Setup you are having, the Environment variable will get varied