DEV Community

kittisuw
kittisuw

Posted on

πŸš€ How to Self-Host n8n with Docker Compose

n8n is a powerful open-source workflow automation tool. If you're deploying it yourself using Docker Compose, it's important to pin the image version for reliability and control.


βœ… Prerequisites

Before you begin, ensure your system has:

  • Docker installed
  • Docker Compose installed
  • A working terminal (Linux, macOS, or WSL on Windows)
  • Basic knowledge of Docker CLI

Check versions:

docker -v
docker compose version
Enter fullscreen mode Exit fullscreen mode

🧱 Step-by-Step Installation

1️⃣ Create a directory

mkdir -p ~/n8n-docker && cd ~/n8n-docker
Enter fullscreen mode Exit fullscreen mode

2️⃣ Create docker-compose.yml

version: "3.7"

services:
  n8n:
    image: n8nio/n8n:1.103.2  # βœ… Pin the version
    ports:
      - "5678:5678"
    environment:
      - GENERIC_TIMEZONE=Asia/Bangkok
      - N8N_BASIC_AUTH_ACTIVE=true
      - N8N_BASIC_AUTH_USER=admin
      - N8N_BASIC_AUTH_PASSWORD=your-password
    volumes:
      - ./n8n_data:/home/node/.n8n
    restart: unless-stopped
Enter fullscreen mode Exit fullscreen mode

🧐 Explanation:

  • volumes: persists your workflows and credentials.
  • restart: unless-stopped: auto-restarts unless manually stopped.
  • image: n8nio/n8n:1.103.2: fixes version to avoid surprises on update.
  • restart: unless-stopped: self restart

3️⃣ Start the container

docker compose up -d
Enter fullscreen mode Exit fullscreen mode

4️⃣ Access n8n

Visit: http://localhost:5678
Login: admin / your-password


πŸ”’ Why You Should Pin the Docker Image Version

Avoid using latest β€” it could break your workflows after unexpected updates.

Behavior Result
latest May auto-update on pull, could introduce breaking changes
:1.103.2 Stable and predictable version

πŸ‘‰ Check Docker Hub tags and release notes.


πŸ›  Upgrade Procedure

  1. Backup the ./n8n_data directory
  2. Update the image tag in docker-compose.yml
  3. Pull and restart and verify system health
docker compose pull
docker compose up -d
docker ps
Enter fullscreen mode Exit fullscreen mode
CONTAINER ID   IMAGE               COMMAND                  CREATED       STATUS       PORTS                    NAMES
923e00afb0bc   n8nio/n8n:1.103.3   "tini -- /docker-ent…"   2 hours ago   Up 2 hours   0.0.0.0:5678->5678/tcp   n8n-n8n-1
Enter fullscreen mode Exit fullscreen mode

βœ… Summary

  • Self-host n8n with Docker Compose
  • Pin the Docker image version
  • Secure access with basic auth
  • Persist data with volume mounts
  • Safe upgrade flow

#n8n #Automation #SelfHosted

Top comments (0)