How to Build AI Agents in n8n with Docker: Step-by-Step Guide

Learn how to self-host n8n with Docker and build an AI agent that fetches and formats Wikipedia data. This step-by-step guide helps API teams automate workflows, with practical tips for integrating AI and enhancing developer productivity.

Ashley Goolam

Ashley Goolam

27 January 2026

How to Build AI Agents in n8n with Docker: Step-by-Step Guide

Looking to automate workflows and boost productivity without deep coding? n8n, an open-source automation platform, lets you connect APIs, data, and AI models in powerful ways. In this guide, you'll learn how to self-host n8n using Docker Desktop and build an AI agent that fetches and formats Wikipedia content—ideal for backend engineers and API-focused teams.

💡 Need more from your API workflows? Apidog generates beautiful API documentation and offers an all-in-one platform for collaborative, high-productivity development. See how Apidog can replace Postman at a better price and help your team deliver faster. Discover integrated API collaboration tools.

button

Cloud vs. Self-Hosting n8n: Which Should You Choose?

n8n offers flexibility—run it in the cloud or self-host. If you prefer not to install Docker Desktop, simply sign up for an account at the n8n Cloud AI Workflow Automation Platform.

For this tutorial, we’ll focus on self-hosting n8n with Docker Desktop, giving you full control over your automation environment.


Setting Up Docker Desktop for n8n

To get started:

  1. Download Docker Desktop from docker.com/products/docker-desktop and install it for your OS.
  2. Open Docker Desktop and create/log into your account.

download docker desktop

Pulling and Running n8n via Docker Desktop

pull n8n on docker desktop

run n8n

create an n8n account

You’re now ready to start building automated AI agents.


Explore n8n's Built-in AI Agent Examples

n8n offers prebuilt AI agent templates. For a quick start, select "Test a simple AI Agent Example." However, this guide walks you through creating an agent from scratch, giving you deeper understanding and flexibility.

n8n home page


Step-by-Step: Build an AI Agent That Fetches Wikipedia Data

We’ll create an AI agent ("Bob") that accepts user input, pulls relevant data from Wikipedia, and formats it using HTML. You can adapt these steps for any automation scenario—from API testing bots to workflow assistants.

  1. Start a New Workflow:
    • Select "Start from Scratch" on the n8n homepage.
    • You’ll see a blank workspace.

blank workflow in n8n


1. Add a Chat Interface

add your first tool in n8n

test chat trigger tool in n8n


2. Add the AI Agent Node

add n8n ai agent

download docker desktop0


3. Connect to an AI Model (OpenAI GPT)

download docker desktop1

download docker desktop2

download docker desktop3

download docker desktop4

download docker desktop5


4. Give Your Agent Short-Term Memory

download docker desktop6

download docker desktop7


5. Integrate Wikipedia Data

download docker desktop8


6. Apply Prompt Engineering

Refine your agent’s instructions for consistent, structured responses.

download docker desktop9

Role: You are a research assistant

User_Input: {{ $json.chatInput }}

Expected_structure: { 'title': 'Your title about what user is looking for', 'body': 'Your content from Wikipedia' }

Task: Your job is to look up information about User_Input from Wikipedia and return the output in JSON format following the Expected_Structure.

7. Format Results with HTML

<!DOCTYPE html>
<html>
<head>
  <meta charset="UTF-8" />
  <title>Generated Document</title>
  <style>
    body { font-family: Arial, sans-serif; margin: 24px; }
    .container { max-width: 700px; margin: auto; background: #fff; padding: 20px; border: 1px solid #eee; border-radius: 8px; }
    h1 { color: #ff6d5a; font-size: 32px; margin-bottom: 12px; }
    p  { color: #333; font-size: 16px; white-space: pre-line; line-height:1.5; }
  </style>
</head>
<body>
  <div class="container">
    <h1>{{ $json.output ? JSON.parse($json.output).title : 'No Title' }}</h1>
    <p>{{ $json.output ? JSON.parse($json.output).body : 'No content available.' }}</p>
  </div>
</body>
</html>

pull n8n on docker desktop0

Your workflow should now look like this:

pull n8n on docker desktop1


Test and Expand Your n8n AI Agent

You’ve built a functional n8n agent that:

Try asking:

pull n8n on docker desktop2


Frequently Asked Questions

Q: Is n8n free to self-host?
A: Yes, n8n’s open-source core is free; paid cloud plans add convenience.

Q: What languages can I use for custom nodes?
A: JavaScript is supported for custom nodes, but most workflows use no-code visual options.

Q: Can n8n connect to other AI models?
A: Yes, integrate OpenAI, Anthropic, or other providers using API keys in the AI nodes.

Q: How do I secure my n8n instance?
A: Use HTTPS, manage API keys, rely on Docker isolation, and enable authentication in n8n’s settings.

Q: Is n8n beginner-friendly?
A: Yes—start with templates, then build step-by-step as shown above.


Conclusion

With your first n8n AI agent up and running, you’ve unlocked the power to automate research, reporting, and more with minimal code. For deeper API testing, collaboration, and documentation, Apidog integrates seamlessly into professional developer workflows—offering the tools API teams need to scale.

button

pull n8n on docker desktop3

Explore more

Pretext.js: The 15KB Library That Makes Text Layout 500x Faster

Pretext.js: The 15KB Library That Makes Text Layout 500x Faster

Pretext.js measures multiline text through pure arithmetic, not DOM reflow. Learn how this 15KB zero-dependency library delivers 500x faster text layout for virtual scrollers, chat UIs, and data grids.

31 March 2026

Qwen3.5-Omni Is Here: Alibaba's Omnimodal AI Beats Gemini on Audio

Qwen3.5-Omni Is Here: Alibaba's Omnimodal AI Beats Gemini on Audio

Qwen3.5-Omni launched March 30 with 113-language speech, voice cloning, and benchmark wins over Gemini 3.1 Pro. Here's what's new and why it matters.

31 March 2026

Hermes Agent: The Better OpenClaw Alternative Is Here

Hermes Agent: The Better OpenClaw Alternative Is Here

Compare Hermes Agent and OpenClaw for MCP, messaging, scheduling, plugins, and API workflows, then see where Apidog fits in the stack.

30 March 2026

Practice API Design-first in Apidog

Discover an easier way to build and use APIs