Konstantinos Antoniou.

← Projects

n8n – Automating My Infrastructure Workflows

⚙️ Step 1 – Installation Overview

I deployed n8n on my Proxmox-based infrastructure as a Docker container inside my Debian VM that hosts most of my automation services. This allows n8n to integrate easily with Docker, Ansible, and my monitoring stack (Grafana, Prometheus, Wazuh).

🐳1. Docker Compose Deployment

I used the following docker-compose.yml file to deploy n8n along with basic persistence and timezone setup:

services:
  postgres:
    image: postgres:15
    container_name: n8n_db
    restart: unless-stopped
    environment:
      - POSTGRES_USER=${DB_POSTGRESDB_USER}
      - POSTGRES_PASSWORD=${DB_POSTGRESDB_PASSWORD}
      - POSTGRES_DB=${DB_POSTGRESDB_DATABASE}
    volumes:
      - /opt/appdata/n8n_db:/var/lib/postgresql/data

  n8n:
    image: n8nio/n8n:latest
    container_name: n8n
    restart: unless-stopped
    ports:
      - 5678:5678
    environment:
      - TZ=${TZ}
      - NODE_ENV=${NODE_ENV}
      - 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}
      - WEBHOOK_URL=${WEBHOOK_URL}
      - N8N_PROTOCOL=${N8N_PROTOCOL}
      - DB_TYPE=${DB_TYPE}
      - DB_POSTGRESDB_HOST=${DB_POSTGRESDB_HOST}
      - DB_POSTGRESDB_PORT=${DB_POSTGRESDB_PORT}
      - DB_POSTGRESDB_DATABASE=${DB_POSTGRESDB_DATABASE}
      - DB_POSTGRESDB_USER=${DB_POSTGRESDB_USER}
      - DB_POSTGRESDB_PASSWORD=${DB_POSTGRESDB_PASSWORD}
    volumes:
      - /opt/appdata/n8n:/home/node/.n8n
      - /var/run/docker.sock:/var/run/docker.sock
    user: root
    entrypoint: /bin/sh -c "apk add docker-cli && n8n"
    depends_on:
      - cloudflared
      - postgres
  cloudflared:
    image: cloudflare/cloudflared:latest
    container_name: N8N_domain
    restart: always
    command: tunnel --no-autoupdate run --token ${TOKEN}
   

networks:
  default:
    external: true
    name: Apps-Network

🔐 Step 2 – Secure Access via Cloudflare Tunnel

Since I use Cloudflare Tunnels for all my internal services, I exposed n8n.black-crab.cc through Cloudflare with automatic SSL encryption.
This way, n8n can be securely accessed from anywhere without port forwarding.


⚡ Step 3 – Creating a Simple Automation Workflow

To test the setup, I built a basic workflow that checks whether Docker containers on my server are running and sends a Telegram notification if one is down.

Screenshot 1: ⚡ Step 3 – Creating a Simple Automation Workflow

Workflow Description:

  • Trigger: Runs every 10 minutes using the Cron node.
  • Action 1: Executes the shell command docker ps -a –format “{{.Names}}: {{.Status}}”.
  • Action 2: Filters and formats the output to have a clear list”.
  • Action 3: Sends an alert message both on my e-mail and on Telegram .

n8n Workflow Breakdown:

1. Cron Node (Trigger)

    • Set to execute every 10 minutes.

2. Execute Command Node

docker ps -a —format ”{{.Names}}: {{.Status}}”

  • Output Example:

grafana: Up 3 hours prometheus: Up 3 hours wazuh: Exited (1)

3. Function Node (Code in JavaScript)

// $json["stdout"] contains the output from the Execute Command node
const output = $json["stdout"];

// Split into lines and remove empty lines
const lines = output.split("\n").filter(line => line.trim() !== "");

// Optional: sort alphabetically (if you want)
lines.sort();

// Combine lines into a single string for alerting
const message = lines.join("\n");

return [
  {
    json: {
      message: message
    }
  }
];

4. Telegram Node (Alert)

    • Sends a message to my Telegram bot:

⚠️ Docker Alert: {{ $json[“message”].includes(“Exited”) ? ”🚨” : ”✅” }} {{ $json[“message”] }}</pre?

    • Also an email notification

Screenshot 2: n8n Workflow Breakdown


📈 Step 4 – Real-world Usability

This workflow gave me real-time visibility into container status without manually checking docker ps each time.
I later expanded this automation to include:

  • Restarting stopped containers automatically
  • Logging container events to Nextcloud
  • Integrating n8n with Prometheus alerts and Grafana webhooks

🧩 Step 5 – Benefits Learned

Through this project, I learned:

  • How n8n can visually chain together APIs, shell commands, and webhooks
  • How to use Docker for modular, easily maintainable automation setups
  • How to expose internal apps securely through Cloudflare
  • How automation reduces manual checks and boosts system reliability

💡 Future Plans

Next, I plan to:

  • Integrate n8n with Ansible playbooks to trigger automated deployments
  • Use webhooks from Grafana alerts to trigger recovery workflows
  • Store automation logs in InfluxDB for visualization