AIAITutorial NO. ---
n8n Ollama tutorial: build a local AI workflow in Docker
Run n8n and Ollama on one Docker Compose network, point the credential at http://ollama:11434 instead of localhost, and build a five-node workflow that summarises an RSS feed with Llama 3.2 and posts the results to a webhook.
Key takeaways
- n8n and Ollama can share one Docker Compose network, so the n8n Ollama credential points at
http://ollama:11434rather thanlocalhost. - The most common failure is networking: inside a container,
localhostmeans the container itself, not your machine. - A summary workflow needs five nodes: Schedule Trigger, RSS Read, Limit, Basic LLM Chain with an Ollama Chat Model, and HTTP Request.
- The AI Agent node is for jobs that need tools. n8n's documentation says at least one tool sub-node must be connected to it.
- Local models keep data on your hardware and cost nothing per token. Cloud chat models are a better fit for long documents, complex reasoning and high volume.
How to connect n8n to Ollama: the short answer
To connect n8n to Ollama, run both in Docker on a shared network, pull a model such as Llama 3.2 3B (a 2.0 GB download), and set the n8n Ollama credential's base URL to http://ollama:11434, not localhost. An Ollama Chat Model powers a Basic LLM Chain.
This guide builds that setup from scratch, using commands checked against n8n's and Ollama's official documentation on 25 October 2026. The finished workflow reads an RSS feed every hour, has a local model summarise each new item, and posts the summaries to a webhook. No data leaves your machine except the final post. If you have never run a local model, start with our hub guide, how to run a local LLM with Ollama.
What you need before you start
- Docker with Compose v2. Docker Desktop on macOS or Windows, or Docker Engine plus the Compose plugin on Linux.
- Enough memory for the model. Llama 3.2 3B is a 2.0 GB download and Llama 3.2 1B is 1.3 GB, according to the Ollama library. Both list a 128K context length and support tool calling.
- Optional GPU. Ollama's FAQ says GPU acceleration in Docker works on Linux, or on Windows with WSL2, and needs the NVIDIA Container Toolkit. It is not available in Docker Desktop on macOS because Docker there has no GPU passthrough. Mac users who want GPU speed should run the native Ollama app and connect n8n to it (see the networking table below).
Step 1: Run n8n and Ollama with Docker Compose
n8n's own installation pages now recommend Docker Compose over a single docker run command. The file below puts both services in one Compose project. Compose creates a private network for the project, and each service can reach the other by its service name.
# docker-compose.yml
services:
ollama:
image: ollama/ollama
container_name: ollama
restart: unless-stopped
ports:
- "127.0.0.1:11434:11434" # optional: lets you test with curl from the host
volumes:
- ollama:/root/.ollama
n8n:
image: n8nio/n8n
container_name: n8n
restart: unless-stopped
ports:
- "127.0.0.1:5678:5678"
environment:
- GENERIC_TIMEZONE=Europe/London
- TZ=Europe/London
- N8N_ENFORCE_SETTINGS_FILE_PERMISSIONS=true
volumes:
- n8n_data:/home/node/.n8n
depends_on:
- ollama
volumes:
ollama:
n8n_data:Some notes on the choices in this file:
GENERIC_TIMEZONEsets the time zone for schedule-based nodes such as Schedule Trigger, andTZsets the container's system clock. Change both to your own zone.- The
n8n_datavolume holds n8n's SQLite database and its encryption key. If you lose the volume, you lose your saved credentials. - Both ports are bound to
127.0.0.1, so only your machine can reach them. n8n's production Compose guide does the same and puts a reverse proxy with TLS in front. N8N_RUNNERS_ENABLEDis not needed. n8n's documentation says it was deprecated in n8n 2.0.
Start the stack, then pull a model into the Ollama container:
docker compose up -d
docker compose exec ollama ollama pull llama3.2:3b
curl http://localhost:11434/api/tags # lists the models Ollama has installedFor an NVIDIA GPU on Linux, Ollama's Docker Hub page gives the single-container form docker run -d --gpus=all -v ollama:/root/.ollama -p 11434:11434 --name ollama ollama/ollama. AMD cards use the ollama/ollama:rocm image with --device /dev/kfd --device /dev/dri.
Prefer a bundle? n8n maintains the Self-hosted AI Starter Kit, a Compose template with n8n, Ollama, the Qdrant vector store and PostgreSQL. It has cpu, gpu-nvidia and gpu-amd profiles, for example docker compose --profile cpu up.
Step 2: Get the networking right (the host.docker.internal pitfall)
Most "n8n can't connect to Ollama" errors come from one detail. Every container has its own localhost. If n8n runs in Docker and you enter http://localhost:11434, n8n looks for Ollama inside its own container and gets "connection refused". n8n's troubleshooting page for the Ollama node lists the correct base URL for each layout:
| Where each part runs | Base URL in the n8n credential | Extra step |
|---|---|---|
| n8n and Ollama in separate containers (this guide) | http://ollama:11434 (the container or service name) | Both containers on the same user-defined network. Compose does this for you. |
| Only n8n in Docker, Ollama native on the host | http://host.docker.internal:11434 | Make Ollama listen on 0.0.0.0. On Linux, start n8n with --add-host host.docker.internal:host-gateway. Docker Desktop sets this up automatically. |
| Only Ollama in Docker, n8n native | http://localhost:11434 | Publish the port with -p 11434:11434. |
| Both native, or both in the same container | http://localhost:11434 | None. If you see ECONNREFUSED ::1:11434, use http://127.0.0.1:11434. |
Source: n8n documentation, "Ollama Model node common issues" and "Ollama credentials", read 25 October 2026.
The ::1 error appears when IPv6 is enabled but Ollama is listening on IPv4 only. Switching to the IPv4 address 127.0.0.1 fixes it, n8n says. For the host-to-container case, remember that Ollama binds to 127.0.0.1 on port 11434 by default. On Linux, run systemctl edit ollama.service, add Environment="OLLAMA_HOST=0.0.0.0:11434" under [Service], then reload systemd and restart the service. On macOS, run launchctl setenv OLLAMA_HOST "0.0.0.0:11434" and restart the app. A server bound to 0.0.0.0 is reachable from your whole network, so keep a firewall in front of it.
If you use n8n's starter kit but run Ollama natively on a Mac, the kit's README says to set OLLAMA_HOST=host.docker.internal:11434 in its .env file and use the same address as the credential's base URL.
Step 3: Add the Ollama credential in n8n
- Open
http://localhost:5678and create the owner account. - Go to Credentials, add a new credential and search for Ollama.
- Set Base URL to
http://ollama:11434. The default ishttp://localhost:11434, which is wrong for this layout. - Leave API Key empty. n8n's docs say the key is only for authenticated proxies such as Open WebUI, where it is sent as a Bearer token.
- Save the credential. If the connection fails, go back to the table above.
Step 4: Build the RSS summary workflow
Summarising does not need tools, so this workflow uses the Basic LLM Chain node. It sends one prompt to the model and returns the answer. Create a new workflow and add these nodes in order:
- Schedule Trigger: run every hour.
- RSS Read: set URL to any feed you are allowed to process. The node returns one item per entry. Fields such as
title,linkandcontentSnippetcome from the feed itself, so check the output panel to see what your feed provides. - Limit: set Max Items to 5 while testing. On a CPU, each summary can take several seconds, and an unfiltered feed can hold dozens of entries.
- Basic LLM Chain: set Prompt to "Define below" and enter the text below in Prompt (User Message). Then click the chain's Model connector and add an Ollama Chat Model that uses your credential and the model name
llama3.2:3b. - HTTP Request: Method
POST, your webhook URL, Send Body on, body content type JSON, with fields such assummary={{ $json.text }}andlink={{ $('Limit').item.json.link }}.
Summarise this news item in two plain sentences for a busy reader.
Do not add facts that are not in the text.
Title: {{ $json.title }}
Text: {{ $json.contentSnippet }}The Basic LLM Chain puts the model's answer in a field called text, which is why the HTTP Request node reads $json.text. The webhook can be your own endpoint, another n8n workflow that starts with a Webhook node, or a chat service's incoming webhook. Discord, for example, expects the message in a content field. Run the workflow once with Execute workflow and look at each node's output before you activate it.
Tuning the Ollama Chat Model
- Sampling Temperature: keep it low (around 0.2) for summaries. n8n's documentation warns that a higher temperature raises the risk of hallucinations.
- Context window: Ollama's FAQ says the default context is 4,096 tokens unless you set
OLLAMA_CONTEXT_LENGTH. Long articles or email threads can be cut off without warning, so trim the input or raise the limit. - Cold starts: Ollama keeps a model in memory for five minutes by default. An hourly schedule therefore reloads the model on every run, and the first call is slower.
OLLAMA_KEEP_ALIVEchanges this, at the cost of memory held between runs.
Summarising email instead of RSS
To summarise email, replace the Schedule Trigger and RSS Read nodes with n8n's Email Trigger (IMAP) node or the Gmail trigger. Then point the prompt at the subject and body fields that the trigger outputs. Strip quoted replies and signatures first, because they quickly use up a 4,096-token context.
Step 5: When to use the AI Agent node instead
The AI Agent node is for tasks where the model has to decide what to do, such as looking something up, calling an API or doing a calculation before it answers. Since n8n 1.82.0, every AI Agent node works as a Tools Agent, and the older agent-type setting is deprecated. n8n's documentation says you must connect at least one tool sub-node. The node's options include a System Message and Max Iterations (default 10). You can also turn on Require Specific Output Format and attach a Structured Output Parser when the next node needs clean JSON.
To try it, add a Chat Trigger, then an AI Agent with the same Ollama Chat Model, and give it one simple tool such as the Calculator or an HTTP Request tool. Use a model whose Ollama library page shows the tools label, as Llama 3.2 does. Small models call tools less reliably than large ones, so keep the tool list short and the descriptions clear. The agent returns its answer in a field called output, not text.
For what an agent loop does under the hood, see our guide on building an AI agent in Python with tool calling. To give an n8n agent access to your own systems, the MCP server tutorial shows how to expose tools over the Model Context Protocol, which n8n's agent documentation also covers. If the agent has to answer from your own documents, the pattern in building a local RAG app with Ollama carries over to n8n's vector store nodes and the Qdrant service in the starter kit.
Local model or cloud model?
Because the model is a separate sub-node, switching from Ollama to a hosted model only means replacing the Ollama Chat Model with another chat model node. The rest of the workflow stays the same. The trade-offs:
| Factor | Local (Ollama) | Cloud chat model |
|---|---|---|
| Data location | Stays on your hardware | Sent to the provider's servers |
| Cost | No per-token fee. You pay for hardware and power. | Billed per token |
| Default context | 4,096 tokens unless raised (Ollama FAQ) | Usually much larger, depending on the model |
| Speed on a CPU | Seconds per item for 1B–3B models, slower for large ones | Fast, but depends on the network |
| Tool calling | Works with tool-capable models, but less reliably on small ones | Generally stronger |
Use local models for private or regulated text, high-volume simple jobs like classifying and summarising, and offline setups. Use a cloud model when the task needs long documents, multi-step reasoning or reliable tool use, or when your hardware cannot run a large enough model. Ollama also offers models with a :cloud tag. These run on Ollama's servers, so they are not local in the privacy sense.
What it means
n8n handles triggers, retries, credentials and integrations, while Ollama provides a private model endpoint. Together they give you an automation stack where the AI step costs nothing per call and the text never leaves your hardware. Most of the work is in the plumbing rather than the AI: one shared Docker network, the right base URL, and a context window big enough for your input. Once the RSS workflow runs, the same structure fits ticket triage, log summaries and inbox digests. You only swap the trigger and the prompt, and you can move to a cloud model later without rebuilding the workflow.
Frequently asked questions
What base URL should I use for Ollama in n8n?
It depends on where each part runs. If n8n and Ollama are separate containers on the same Docker network, use the Ollama container name, such as http://ollama:11434. If only n8n is in Docker, use http://host.docker.internal:11434. If both run natively, use http://localhost:11434, or http://127.0.0.1:11434 if you get an ECONNREFUSED ::1 error.
Why does n8n say connection refused when connecting to Ollama?
Inside a Docker container, localhost refers to the container itself, so n8n cannot find Ollama there. Use the Ollama container name or host.docker.internal instead. If Ollama runs on the host, make it listen on 0.0.0.0, because by default it binds to 127.0.0.1 only.
Does the n8n AI Agent node work with Ollama?
Yes. Attach an Ollama Chat Model sub-node to the AI Agent node and connect at least one tool sub-node, which n8n's documentation requires. Use a model that supports tool calling, such as Llama 3.2. For simple summarising without tools, the Basic LLM Chain node is easier.
Is running n8n with Ollama free?
n8n can be self-hosted, and Ollama has no per-token charge for models that run locally. You still pay for your own hardware and electricity. Ollama models with a :cloud tag run on Ollama's servers, so they are not local.
Sources
- n8n documentation: Ollama Chat Model node
- n8n documentation: Ollama credentials
- n8n documentation: Ollama Model node common issues
- n8n documentation: Docker installation
- n8n documentation: Docker Compose setup
- n8n documentation: AI Agent node
- n8n documentation: Tools Agent
- n8n documentation: Basic LLM Chain node
- n8n documentation: RSS Read node
- n8n Self-hosted AI Starter Kit on GitHub
- Ollama image on Docker Hub
- Ollama documentation: FAQ
- Ollama API reference
- Ollama library: llama3.2