Self-Host n8n with Local Ollama: Zero-Cost AI Workflows (2026)
I've been running n8n + Ollama locally for a few months. No OpenAI bill. No data leaving my network. The setup takes under 20 minutes — except for the Docker networking part, which cost me an hour the first time. This post skips the fluff.
Table of Contents
What n8n and Ollama Do
n8n is a self-hostable workflow automation tool — Zapier, but you own the server. It connects triggers, logic, APIs, databases, and AI models via a visual node editor. Refer to the n8n Docs for official workflow node definitions.
Ollama is a local LLM runtime. It downloads model weights, loads them into memory, and exposes a REST API on port 11434. Any app that makes HTTP requests can talk to it. Grab the installer from the Ollama Download page.
Trigger → n8n → Ollama API (:11434) → Local LLM → Output
Real reasons to use this stack: no per-token cost, data stays local, works offline. The honest tradeoff: a 7B model on an M2 MacBook is slower and weaker than GPT-4o. Use local where privacy or cost matters; use cloud where quality ships to users.
Related Reading: When to Use Cloud LLMs Instead (Claude Code CLI vs Cursor)
Hardware Checklist
| RAM | What Runs |
|---|---|
| 8 GB | 1B–3B models (llama3.2:3b, qwen2.5:3b) |
| 16 GB | 7B models comfortably (llama3.1:8b, qwen2.5:7b) |
| 32 GB+ | 13B–30B; 70B+ needs a GPU on top |
SSD is non-negotiable — models are 2–40 GB. Apple Silicon is great here: GPU and CPU share the same memory pool, so a 16 GB M2 runs 7B models faster than most 16 GB Intel machines.
Install Ollama and Pull a Model
macOS / Linux:
curl -fsSL https://ollama.com/install.sh | sh
Windows: grab the installer at ollama.com/download.
Confirm it's alive:
curl http://localhost:11434
# Returns: "Ollama is running"
Pull a model:
ollama pull llama3.2 # 3B — good for 8 GB
ollama pull qwen2.5:7b # 7B — better quality, needs 16 GB
ollama pull codellama:7b # Code-specific tasks
Quick test:
ollama run llama3.2 # Type a prompt. /bye to exit.
curl http://localhost:11434/api/tags # Lists your pulled models
✅ Ollama running | ✅ Model pulled | ✅ API accessible
Read: Claude code CLI setup - Terminal AI Agent vs Cursor IDE
Run n8n with Docker Compose
I run Ollama directly on the host for GPU access. n8n lives in Docker. Here's my working docker-compose.yml:
version: '3.8'
services:
n8n:
image: docker.n8n.io/n8nio/n8n
ports:
- "5678:5678"
volumes:
- n8n_data:/home/node/.n8n
extra_hosts:
- "host.docker.internal:host-gateway" # Linux only
volumes:
n8n_data:
docker compose up -d
Open http://localhost:5678, create your account (local, no cloud), and you're in.
✅ n8n running
Read: Open-Weight Reasoning Models vs. Proprietary APIs: Cost, Latency & Privacy Benchmark
Connect n8n to Ollama
Go to Settings → Credentials → Add Credential → Ollama.
The Base URL field is where people get stuck. Use this lookup matrix:
| n8n Location | Ollama Location | Base URL |
|---|---|---|
| Host machine | Host machine | http://localhost:11434 |
| Docker | Host machine | http://host.docker.internal:11434 |
| Docker | Docker (same network) | http://ollama:11434 |
Click Test. Green = connected. ✅
Fix Docker Networking
This is where Docker breaks most setups. Here's why: inside a container, localhost refers to the container itself — not your machine. So localhost:11434 looks for Ollama inside the container, where nothing is listening.
- macOS / Windows (Docker Desktop):
host.docker.internalresolves automatically. Just use it. - Linux: It doesn't exist by default. The
extra_hostsline in the compose file above handles it. Check the Docker extra_hosts documentation for configuration syntax.
--add-host=host.docker.internal:host-gateway
If running both containers in Docker, put them on the same network and reference Ollama by service name (http://ollama:11434). Note that GPU passthrough in this scenario requires the NVIDIA Container Toolkit on Linux.
5 Workflows Worth Building
- Email summarizer: Gmail trigger → Ollama → log summary to Google Sheets
- Document summarizer: Drive PDF → extract text → Ollama → save back to Drive
- Content draft generator: Webhook (topic input) → Ollama → Notion
- RAG / knowledge base: Add Qdrant. Explore the pre-built n8n Self-Hosted AI Starter Kit to launch n8n + Ollama + Qdrant + PostgreSQL automatically.
- Private chat assistant: Telegram/Webhook → Ollama with custom system prompt → reply. Nothing touches a cloud API.
Troubleshooting Table
| Error | Cause | Fix |
|---|---|---|
| Connection refused | Ollama not running | ollama serve |
| localhost fails | n8n is in Docker | Use host.docker.internal:11434 |
| host.docker.internal fails on Linux | Missing mapping | Add extra_hosts: host-gateway |
| Model not found | Not pulled | ollama pull <model> |
| Credential passes, workflow fails | Name mismatch | Run ollama list — names must match exactly |
| Slow responses | Model too large | Switch to Q4-quantized variant |
| OOM errors | Not enough RAM | Drop to 3B model or add swap |
| Workflows lost on restart | No volume | Mount n8n_data (in compose above) |
Local vs Cloud
| Factor | Ollama + n8n | Cloud API |
|---|---|---|
| Cost per call | Zero | Pay per token |
| Data privacy | Your machine | Provider's servers |
| Offline use | Yes (after download) | No |
| Setup effort | Higher | Minimal |
| Model quality | 7B–70B local | Frontier models available |
| Scaling | Your hardware ceiling | Effectively unlimited |
FAQ
Can I run n8n and Ollama for free?
Yes. n8n self-hosted is free under its fair-code license. Ollama is open source. Real costs are electricity and your hardware.
Open Source Cursor Alt for CLI
What URL does n8n use to reach Ollama?
Host-to-host: http://localhost:11434. Docker-to-host: http://host.docker.internal:11434.
Why does localhost fail inside Docker?
localhost inside a container is the container itself, not your host machine. Ollama runs on the host, creating a network mismatch. Use host.docker.internal.
Which model should I start with?
8 GB RAM → llama3.2:3b. 16 GB → qwen2.5:7b. Pick what fits in your free RAM after your OS takes its share.
Does n8n support Ollama natively?
Yes. Built-in credentials and an Ollama Chat Model node are available out of the box.
Comments
Post a Comment