Skip to content

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


๐Ÿ“ 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