Refuse connection to 127.0.0.1:27017 and 127.0.0.1:11434

MongoDB and Ollama Component cannot connect to the default port in localhost.

Ollama : the service refuse the connection - perhaps it is offline
MongoDB: connect ECONNREFUSED 127.0.0.1:27017

Both use 127.0.0.1 in the setting account.
Ollama running locally, MongoDB running in Docker
The same condition was running well on another platform, except N8N

Appreciate any help… TIA

Information on your n8n setup

  • **n8n version: the latest
  • **Database (default: SQLite):SQLite
  • **n8n EXECUTIONS_PROCESS setting (default: own, main):main
  • **Running n8n via (Docker, npm, n8n cloud, desktop app):docker
  • **Operating system: ubuntu

Hey @dilitimor hope all is well. Welcome to the community.

Let’s start with the Mongo. It also runs in docker. N8N in one container, Mongo in different, I assume. In this case 127.0.0.1 is not the right address to point to for the n8n to reach it. If you are using docker compose and both containers are attached to the same network - you should use the container’s name instead.

Next - Ollama, you said it is running locally, meaning on the same host which runs the docker. In this case 127.0.0.1 is also not the correct IP to use - what you should use instead is (depending on the host OS) either host.docker.internal or the ip address of the docker0 interface of the host or the ip address of the default gateway of the container.

Hi @jabbson Thanks for your quick help. I am still working on your solution.

1 Like

Hi @jabbson here is my network inspect
docker network inspect host
[
{
“Name”: “host”,
“Id”: “2c450584d8f597c44270f6126ea40821dd171627787d1f42bfa2e30ddea32768”,
“Created”: “2025-07-26T14:36:48.392008389Z”,
“Scope”: “local”,
“Driver”: “host”,
“EnableIPv4”: true,
“EnableIPv6”: false,
“IPAM”: {
“Driver”: “default”,
“Options”: null,
“Config”: null
},
“Internal”: false,
“Attachable”: false,
“Ingress”: false,
“ConfigFrom”: {
“Network”: “”
},
“ConfigOnly”: false,
“Containers”: {
“3f145c3bf11a9c592018c058bae9cee888079cad6e5bf3770dfa103bb9777153”: {
“Name”: “mongodb-cengkeh”,
“EndpointID”: “0e0e9e7c99d8af70cf2f9e5df143e11033ac20d4e1d719026762a97c3a834e70”,
“MacAddress”: “”,
“IPv4Address”: “”,
“IPv6Address”: “”
},
“e658a2762e9bd854b193718b6d489bc61451f90ef384d6647412271fec49d8c0”: {
“Name”: “n8n-bawangmerah”,
“EndpointID”: “be4c7f9ecddb29b2818511fa6e662c32b2a59d20791cdb173903e977877581b8”,
“MacAddress”: “”,
“IPv4Address”: “”,
“IPv6Address”: “”
}
},

now, both of them already on the same network.

Is there a specific reason they are connected to the host network?

for simplicity, i am not sys-admin.

Now mongodb credential account work, but ollama ain’t yet

Actually if all your Docker containers are connected to the host network, then they all share the host’s network stack, including the loopback interface (127.0.0.1). If n8n cannot connect to 127.0.0.1:11434, then either

  • one of them is not connected to the host network, or
  • ollama is not running, or
  • ollama is not listening on port 11434

What would be the output of the following command ran in the terminal:

sudo netstat -tulnp | grep 11434

If nothing shows up, go to Ollama settings and see if there is a slider for something called along the lines of “Expose Ollama to the network”. It has to be enabled.

tcp 0 0 127.0.0.1:11434 0.0.0.0:* LISTEN 1777/ollama

Well it is listening, so when you try to create ollama credentials in n8n using this IP and port what error do you get? I think you only mentioned Mongo previously

The host is unreachable, perhaps the server is offline

From the same terminal, run

curl http://127.0.0.1:11434

What does it say back?

it is say:

Ollama is running

Can you show a screenshot of a browser window with n8n, where you try to create credentials for ollama?

And you are sure you are running only a single instance of n8n, no second n8n, or cloud, does your browser URL start with http://127.0.0.1:5678?

I am sure,

ok, let’s summarize what we have so far:

  • n8n runs in docker and is exposed through port 5678
    • verified from a browser URL
  • n8n is bound to the host network in docker, exposing it directly to the host’s networking stack
  • ollama runs locally and is exposed for 0.0.0.0 through port 11434
    • verified with netstat
  • ollama is responsive locally in terminal
    • verified with curl against 127.0.0.1:11434
  • an attempt to create credentials in n8n for ollama and pointing it to 127.0.0.1:11434 results in The host is unreachable, perhaps the server is offline error

Next I would try to connect to the n8n docker container and see what we can reach from there. Before we go there, another thing that we could try:

http://127.0.0.1;11434 to http://localhost:11434 result:
The host is unreachable, perhaps the server is offline

docker -ps -a
CONTAINER ID IMAGE COMMAND CREATED STATUS PORTS NAMES
3f145c3bf11a mongodb/mongodb-atlas-local “/usr/local/bin/runn…” 2 hours ago Up 2 hours (healthy) mongodb-cengkeh
e658a2762e9b n8nio/n8n “tini – /docker-ent…” 3 hours ago Up 2 hours n8n-bawangmerah
0d24230d5f88 mongodb/mongodb-atlas-local:latest “/usr/local/bin/runn…” 10 days ago Exited (2) 24 hours ago mongodb-kunyit
975e612daa11 n8nio/n8n:latest “tini – /docker-ent…” 10 days ago Exited (0) 24 hours ago n8n-micin

Ok, let dig more:

To connect to the container, let’s do this - in terminal, run

docker exec -it --user root e658a2762e9b /bin/sh

the prompt will change to

/home/node #

update package list and install curl

apk update && apk add curl

now try to run the same curl command we did earlier:

curl http://127.0.0.1:11434

also run

netstat -tulnp

and show me what you got.

curl http://127.0.0.1:11434
Ollama is running

netstat -tulnp