~/t/g/self-hosting $

n8n fetch failed with Ollama? Check the Docker address

gist Use Ollama's name on a shared Docker bridge, test /api/tags from inside n8n, then check the installed model and workflow.

contents
  1. Step 1: Put both services on the same bridge
  2. Step 2: Test from the n8n container
  3. Step 3: Save the Ollama credential and test a model
  4. Compare connection options
  5. Common questions

When n8n reports fetch failed while Ollama works elsewhere, check the address from inside n8n and use Ollama’s alias on a shared Docker bridge. In separate containers, localhost points back to n8n (n8n’s Docker troubleshooting documentation).

I run n8n and Ollama as containers on my Unraid box.

You need both containers running, access to their network settings, and a terminal on the Docker host. Keep the current container configuration and model storage when changing network settings.

Step 1: Put both services on the same bridge

Attach both containers to the same user-defined Docker bridge. Save that network choice in the configuration that starts each container, so it survives recreation.

Docker’s default network named bridge differs from a user-defined bridge. A user-defined bridge provides automatic DNS lookup for container names and network aliases. Containers on it can reach each other on internal ports without publishing those ports to the host. Docker bridge documentation. For more on picking a network mode, see Docker host or bridge networking.

Give the Ollama container a network alias such as ollama.example. Configure that alias on the shared network.

The connection should follow this path:

n8n container → Shared Docker bridge → ollama.example:11434

Check that Ollama listens on an interface reachable from that bridge. The official Ollama Docker image is already configured to listen on all container interfaces. A custom configuration may override that setting. n8n’s separate-container instructions.

For a listener restricted to loopback, adjust OLLAMA_HOST in Ollama’s service configuration and restart the service. 0.0.0.0 means “listen on all IPv4 interfaces”; use the reachable container name as the client destination. Ollama server configuration.

Diagram: n8n reaches Ollama by its bridge name; loopback refers to n8n itself.
Inside n8n, localhost is n8n. Ollama is one hop away, by its name on the shared bridge.

Step 2: Test from the n8n container

A successful request from your laptop checks your laptop’s route. Test from the container that will make the workflow request.

Replace n8n.example with your n8n container name. Replace ollama.example if you configured a different alias. This command uses Node inside the running container through Docker exec:

docker exec n8n.example node -e '
(async () => {
  for (const base of [
    "http://127.0.0.1:11434",
    "http://ollama.example:11434"
  ]) {
    try {
      const response = await fetch(base + "/api/tags", {
        signal: AbortSignal.timeout(5000)
      });
      console.log(base, response.status, await response.text());
    } catch (error) {
      console.log(base, error.cause?.code ?? error.name);
    }
  }
})();
'

The first address checks n8n’s own loopback. The second checks Ollama through the shared bridge.

Result Meaning Next check
ECONNREFUSED The connection was rejected at that address and port. Check the destination, listener and whether Ollama is running.
ENOTFOUND or EAI_AGAIN The name could not be resolved. Check the shared network and configured alias.
Timeout The request did not finish within five seconds. Check routing, filtering and service responsiveness.
HTTP error An HTTP server answered. Check the path, authentication or proxy response.
HTTP 200 with models: [] Ollama is reachable, but its model list is empty. Install a model in that Ollama instance before testing generation.
HTTP 200 with model entries Ollama is reachable and lists available models. Select the exact model name in n8n.

GET /api/tags lists models. It does not generate a response or check agent tool support.

From n8n, loopback is refused while ollama.example returns an empty model list; the service is reachable before a model is installed
Run from inside n8n: localhost is refused, the bridge name answers. The empty model list just means no model is installed yet.
docker exec n8n.example node -e 'fetch("http://127.0.0.1:11434/api/tags").catch(error => console.log(error.cause.code))'
ECONNREFUSED

ECONNREFUSED means this caller has no Ollama listener at its own loopback address.

Step 3: Save the Ollama credential and test a model

Open the Ollama credential used by your node. For the configured bridge alias, enter this Base URL:

http://ollama.example:11434

Use the instance origin. Leave /api/tags, /api/chat and /v1 off this Ollama credential’s Base URL.

Leave API Key empty for a direct local instance without authentication. If an authenticated proxy sits in front of Ollama, supply its required key through the credential field. n8n’s Ollama credential documentation.

Save the credential. Select a model listed by /api/tags, including its tag. If the list is empty, add a model to the same Ollama instance first.

Start with a small manual workflow using a Basic LLM Chain and a short prompt. Check generation before adding tools or other services.

The Ollama Model node lacks tool support and belongs with a Basic LLM Chain. An AI Agent needs a compatible chat model node and a model that supports tool calling. Check both separately. A working model-list request cannot confirm them. n8n’s Ollama Model documentation, Ollama tool-calling documentation.

Compare connection options

Option When it fits Tradeoff
Direct Ollama connection n8n needs models from one Ollama instance. Few moving parts, but the network, model and node must all match.
LiteLLM endpoint Several clients need a shared model gateway. Adds a proxy and another connection to check. Its OpenAI-compatible endpoint needs a matching n8n integration.
Another local inference host Models run on a separate machine or service. Check the route from n8n and match the node to the host’s API format.

LiteLLM’s gateway documentation describes its OpenAI-compatible interface, and its Ollama provider documentation covers the upstream connection. Adding a proxy still requires that proxy to reach Ollama; the LiteLLM and Ollama guide covers that setup.

Common questions

Why does Ollama work in a terminal but fail in n8n?

The terminal and n8n may use different network contexts. A host terminal can reach a host listener through loopback. A separate n8n container has its own loopback. Repeat the request inside n8n using the destination configured in its credential.

Will changing localhost to 127.0.0.1 fix it?

Only when Ollama is reachable through the same network namespace and the problem is IPv6 loopback resolution. In separate bridge containers, both addresses point back to n8n. Use Ollama’s container name or alias instead. n8n’s loopback troubleshooting.

Does OLLAMA_ORIGINS fix connection refused?

No. OLLAMA_ORIGINS controls allowed browser origins. OLLAMA_HOST controls the listener address. Browser-origin settings cannot create a missing TCP listener. Ollama’s FAQ.

What if Ollama runs directly on the Docker host?

Use a host address reachable from n8n. Docker Desktop provides a host-access name automatically; Docker Engine on Linux may need an explicit host-gateway mapping. Ollama must also listen on an interface the container can reach. Follow n8n’s host-running Ollama instructions.

Why does the credential connect but the agent fail?

A credential check can succeed before generation or tool use fails. Check the exact model name, the selected node and tool-calling support. Test a plain prompt first, then add the agent’s tools.

Do I need to publish port 11434?

Not for two containers communicating on the same user-defined bridge. Keep Ollama’s listener private. Its local API requires no authentication, so protect any endpoint exposed beyond that network. Docker bridge documentation, Ollama authentication documentation.

Related: self-hosting guides · guide index.

../self-hosting/ every Self-hosting guide