# n8n Docker Ollama Connection Refused: Host Alias Fix

*Originally published at* [*techpotions.com*](https://techpotions.com/lab/n8n-docker-ollama-connection-refused)*.*

When n8n runs in Docker and tries to reach Ollama, the "connection refused" error is almost always because Ollama binds only to `127.0.0.1` and the n8n container can't see it. Bind Ollama to all interfaces with `OLLAMA_HOST=0.0.0.0` and use your host machine's IP address (or `host.docker.internal` on Docker Desktop) as the Base URL in the n8n Ollama credential.

Applies to n8n and Ollama current versions as of November 2026.

## Why n8n Docker Ollama connection refused happens: Ollama listens on localhost

The most direct cause: Ollama serves on port `11434`, but only on the loopback interface. You can confirm this from your host: `curl http://localhost:11434/api/tags` returns model data. From inside the n8n container, `curl http://localhost:11434/api/tags` fails with `ECONNREFUSED`.

**Fix:** Stop Ollama and restart it with the environment variable that tells it to listen on all interfaces:

```bash
OLLAMA_HOST=0.0.0.0 ollama serve
```

If you use systemd, add the variable to the service unit file (e.g., `/etc/systemd/system/ollama.service.d/override.conf`):

```ini
[Service]
Environment="OLLAMA_HOST=0.0.0.0"
```

Then `sudo systemctl daemon-reload && sudo systemctl restart ollama`. Test from your host with `curl http://<host-ip>:11434/api/tags` to confirm it answers on the IP, not just localhost.

## The n8n Docker container still uses localhost as the Ollama base URL

After Ollama binds to `0.0.0.0`, the connection still fails if your n8n Ollama credential contains `http://localhost:11434`. Inside the n8n container, localhost refers to the container's own loopback, not the host machine's.

**Fix:** Replace the Base URL in the credential:

- **Docker Desktop (Windows/macOS):** `http://host.docker.internal:11434`
- **Linux:** use the host's IP address on the Docker bridge. Find it with `ip addr show docker0` or `ip route | grep default`; a common value is `172.17.0.1`. Alternatively, bind the hostname `host.docker.internal` manually by adding an `extra_hosts` entry to your n8n Compose service:

```yaml
services:
  n8n:
    # other config...
    extra_hosts:
      - "host.docker.internal:host-gateway"
```

Then use `http://host.docker.internal:11434` as the Base URL. This trick works on Linux too, because host-gateway resolves to the host's IP automatically.

## host.docker.internal isn't available on Linux

If you get a "Name or service not known" error in the n8n container when using `host.docker.internal`, and you haven't added the `extra_hosts` mapping, the alias isn't built in on your Docker Engine.

**Fix:** Add the `extra_hosts` section shown above, or note the host's IP and use it directly. Inside the n8n container you can often retrieve the host's Docker bridge IP with:

```bash
docker exec n8n-n8n-1 ip route | grep default | awk '{print $3}'
```

Then set the Ollama Base URL to `http://<that-ip>:11434`.

If you're running n8n in the official [Docker Compose deployment](https://docs.n8n.io/deploy/host-n8n/install-options/install-using-docker-compose), the service is named `n8n`. Add the `extra_hosts` key directly to that service definition, alongside its volumes and environment variables.

## How to confirm the fix

**Verify Ollama is reachable from the n8n container.**

```bash
docker exec n8n-n8n-1 wget -qO- http://host.docker.internal:11434/api/tags
```

You should see a JSON array with your pulled models. If `wget` isn't available, use `curl` inside the container or install `wget` temporarily.

- In the n8n UI, create a [Chat Model node](https://docs.n8n.io/integrations/builtin/cluster-nodes/sub-nodes/n8n-nodes-langchain.lmollama/common-issues/) (or the Ollama model node), set the credential to the new Base URL, and test the connection. n8n will list available models if the connection works.
- Run a simple workflow that sends a test message; a successful response confirms full end-to-end connectivity.

Once your local AI pipeline is stable, building client-facing automated workflows becomes straightforward. Our [n8n automation agency solutions](https://techpotions.com/solutions/n8n-automation-agency) help you scale that work without the toil.

## FAQ

### How do I find my host machine's IP address inside a Docker container?

From inside the n8n container, run `docker exec n8n-n8n-1 sh -c 'apt update && apt install -y iproute2 && ip route show default'`. The IP after `via` is the host gateway. On the host itself you can also run `hostname -I` and use one of the displayed IPs (excluding the Docker bridge if both machines are on the same physical network).

### Why does OLLAMA_HOST need to be 0.0.0.0?

It binds Ollama to all available network interfaces, including the Docker bridge and physical network adapters. Only then can the n8n container (or any other machine on the network) reach Ollama. A localhost-only bind blocks all external traffic.

### Can I run Ollama and n8n in Docker containers on the same network instead of using the host?

Yes. Create a Docker network, attach both containers, and make sure Ollama binds to `0.0.0.0` (or the container name). Then configure the n8n Ollama credential to use the Ollama container name (e.g., `http://ollama:11434`). This is an alternative to running Ollama on the host.
