Skip to content
New: a free website for your business, live in 48 to 72 hoursWorkflow automation on n8n and Claude, built for your businessFixed price, agreed before we start · Live in 5 to 10 business days30-day money-back guarantee on every planProfessional firms · Agencies · E-commerceYou own every workflow, in your own n8nClaude API: your data is not used for trainingHuman approval on every sensitive stepFree automation audit, no obligation
PURIST
30 days
Money-back window
14 h/wk
Modeled time saved
99.97%
Uptime SLA
< 7 days
Deploy time
PURIST AI
Claude Opus 4.7 · n8n v1.71 · <80ms
What type of business are you running? I'll show you exactly which processes we'd automate first and your estimated ROI.
Powered by n8n + Claude Opus 4.7 Get my free automation plan →
Fix ECONNREFUSED in n8n: Docker, localhost and 127.0.0.1
Guides 6 min read · 1,180 words

Fix ECONNREFUSED in n8n: Docker, localhost and 127.0.0.1

"connect ECONNREFUSED 127.0.0.1" in n8n almost always means localhost points to the wrong machine. The exact fix for Docker Desktop, Linux, Compose stacks and n8n Cloud.

Steve, founder of PURIST

November 6, 2026

PURIST: Stuck on n8n? Our n8n experts fix and build workflows like this one, at a fixed price →

"connect ECONNREFUSED 127.0.0.1:5000" is one of the most searched n8n errors, and it is rarely a bug in n8n. The node reached a machine, but nothing was listening on that port. Nine times out of ten the machine is the wrong one: inside a Docker container, localhost means the container itself.

In short. Inside the n8n container, localhost is the container, not your computer. On Docker Desktop (Mac or Windows) use http://host.docker.internal:PORT. On Linux add host.docker.internal:host-gateway to the container's extra hosts. For another container in the same Compose stack, use its service name and internal port. Outside Docker, try 127.0.0.1 instead of localhost. On n8n Cloud, local services are unreachable: expose them through a tunnel.

Fix ECONNREFUSED in n8n: Docker, localhost and 127.0.0.1: workflow diagram
Inside a container, localhost is the container itself. Use host.docker.internal or the service name. Illustration: PURIST.

What ECONNREFUSED means

The documentation defines it precisely: the node reaches a host but the target port has no listener, so the TCP connection is actively refused. It is not a DNS failure, not a timeout and not a firewall silently dropping packets. That narrows the search to "wrong host" or "service not running on that port".

Case 1: n8n in Docker, the service on your computer

A request to http://localhost:5000 from the n8n container lands on port 5000 of the container, where nothing listens.

Docker Desktop (Mac, Windows): use the special hostname that Docker adds automatically:

text
http://host.docker.internal:5000

Linux: that hostname is not added by default. Add it in docker-compose.yml:

yaml
services:
  n8n:
    image: n8nio/n8n
    extra_hosts:
      - "host.docker.internal:host-gateway"

or with docker run --add-host=host.docker.internal:host-gateway. The service on the host must also listen on an interface the container can reach, not only on 127.0.0.1 of the host.

Fix ECONNREFUSED in n8n: Docker, localhost and 127.0.0.1: node settings
The docker-compose change that makes the host reachable from n8n on Linux, and how to test it. Illustration: PURIST.

Case 2: the service is another container

In the same Compose stack, containers reach each other by service name. If your stack defines postgres and my-api, use:

text
http://my-api:5000
postgres:5432

Use the container's internal port, not the port published in the ports: mapping. The same applies to database credentials: Host postgres, not localhost.

Case 3: no Docker, localhost still refused

On Node.js 17 and later, localhost can resolve to the IPv6 address ::1 first. If the target only listens on IPv4 127.0.0.1, the IPv6 attempt is refused and the fallback does not always happen inside the HTTP Request node. Use http://127.0.0.1:PORT explicitly.

Case 4: n8n Cloud

Workflows on n8n Cloud run on n8n's infrastructure. There is no path to localhost on your computer. Expose the local service through a tunnel and use the public tunnel URL, or host the service somewhere reachable.

Verify before you rerun

The documentation suggests testing from inside the n8n container:

bash
docker exec -it n8n wget -qO- http://host.docker.internal:5000/health

If wget succeeds, the HTTP Request node will too. If it also says "connection refused", the problem is the network or the target service, not n8n. Then check that the service runs (docker ps, systemctl status) and listens on the expected port.

Quick reference

Where n8n runsWhere the service runsAddress to use
Docker DesktopYour computerhost.docker.internal:PORT
Docker on LinuxThe hosthost.docker.internal:PORT with extra_hosts
Docker ComposeAnother service in the stackservice-name:INTERNAL_PORT
npm on your computerYour computer127.0.0.1:PORT
n8n CloudYour computerA public tunnel URL

For other status codes and network errors, our HTTP Status Explainer tells you what each one means and what to check first.

Worked example: n8n and Postgres in one Compose stack

The most common version of this error is a database credential that uses localhost.

yaml
services:
  postgres:
    image: postgres:16
    environment:
      - POSTGRES_USER=app
      - POSTGRES_PASSWORD=change-me
      - POSTGRES_DB=app
  n8n:
    image: n8nio/n8n
    depends_on:
      - postgres

In the n8n Postgres credential:

FieldWrongRight
Hostlocalhostpostgres (the service name)
Portthe published host port, if different5432 (the container's port)

Containers on the same Compose network reach each other by service name. The ports: mapping only matters for connections from outside Docker.

Is the service actually listening?

ECONNREFUSED also appears when the address is right but the service is down or bound to the wrong interface. On the machine that runs the service:

bash
ss -ltnp | grep 5000
  • 127.0.0.1:5000: only reachable from the same machine. A container cannot reach it through host.docker.internal. Bind the service to 0.0.0.0 (and protect it with a firewall) or put it in the same Docker network.
  • 0.0.0.0:5000 or *:5000: reachable from containers through the host gateway.
  • Nothing listed: the service is not running.

Same error, other nodes

The cause and the fix are identical for the Postgres, MySQL, Redis, SMTP and any other node that connects to a host: inside Docker, localhost is the n8n container. The n8n documentation gives the same fix for the MySQL node.

Troubleshooting table

SetupError targetFix
Docker Desktop, service on your computer127.0.0.1:PORThost.docker.internal:PORT
Docker on Linux, service on the host127.0.0.1:PORTextra_hosts: host.docker.internal:host-gateway and bind the service to 0.0.0.0
Compose, another servicelocalhost:PORTservice-name:INTERNAL_PORT
No Docker, Node.js 17+::1:PORTUse 127.0.0.1
n8n CloudAny local addressExpose the service publicly or through a tunnel
Correct address, still refusedService down or bound to 127.0.0.1Start it; bind to the right interface

Frequently asked questions

Why does n8n say ECONNREFUSED 127.0.0.1?

Inside Docker, 127.0.0.1 is the n8n container itself. Nothing listens on that port there. Use host.docker.internal or the other container's service name.

Does host.docker.internal work on Linux?

Not by default. Add host.docker.internal:host-gateway to the container's extra hosts.

Can n8n Cloud connect to my local database?

No. Cloud workflows cannot reach your machine. Use a tunnel or a hosted database.

How do I connect n8n to Postgres in the same Docker Compose stack?

Use the service name as host (for example postgres) and the internal port 5432 in the n8n Postgres credential.

What does ECONNREFUSED ::1 mean in n8n?

::1 is the IPv6 localhost. On Node.js 17+, localhost can resolve to IPv6 first. If the target listens only on IPv4, use 127.0.0.1 explicitly.

Do I need to publish ports for containers to talk to each other?

No. Containers on the same Docker network talk through service names and internal ports. Published ports are for access from outside Docker.

Why does it work with curl on the server but not in n8n?

curl on the server uses the server's localhost; n8n in Docker uses the container's. Test from inside the container with docker exec.

Tags

n8neconnrefuseddockerself-hostederror
Steve, founder of PURIST

Steve founded PURIST, a workflow automation studio working with n8n, Make and Claude AI, and is the point of contact on every project. Prices and features in our articles come from vendor documentation and public pricing pages. How we research and score tools.

Complete guide

Automation Tools & Platforms

11 min read n8n Code Node: 15 JavaScript Examples You Can Copy and … 8 min read n8n Code Node With Multiple Inputs: 3 Methods That Work 7 min read Fix "Cannot find module" in the n8n Code Node (npm Pack… 7 min read n8n Code Node Errors Fixed: "Code doesn't return items … 7 min read $env and Credentials in the n8n Code Node: What Works a… 7 min read n8n Code Node Binary Data: Read, Change and Return File… 7 min read Python in the n8n Code Node (n8n 2.x): Setup, Syntax an… 7 min read Fix n8n "The requested webhook is not registered" (Test… 6 min read n8n Webhook URL: Test vs Production, and How to Change … 7 min read n8n Respond to Webhook: Return JSON, Status Codes, Redi… 8 min read Secure an n8n Webhook: Header Auth, Basic Auth, JWT and… 7 min read n8n Webhook Not Working? 10 Causes and How to Fix Each … 7 min read n8n HTTP Request Pagination: Every Pattern With Working… 7 min read n8n HTTP Request Authentication: API Keys, Bearer Token… 7 min read n8n HTTP Request Timeout and "Aborted" Errors: Causes a… 7 min read Upload and Download Files With the n8n HTTP Request Nod… 6 min read n8n 429 Too Many Requests: Batching, Retries and Rate L… 6 min read Fix redirect_uri_mismatch for n8n OAuth2 Credentials (G… 7 min read n8n Expression Errors Fixed: "Referenced node is unexec… 6 min read Anatomy Claude skill: what it is, how to install it, an… 5 min read How to explain a business process with the Anatomy skil… 5 min read Anatomy vs Mermaid vs Excalidraw: which to explain a wo… 14 min read n8n LinkedIn Job Automation: Auto-Apply, Track, and Fol… 16 min read n8n HTTP Request Node: Complete Documentation and Examp… 18 min read The future of automation: how our engineering team is s… 8 min read n8n vs Make vs Zapier: the honest comparison your busin… 11 min read n8n vs Make vs Zapier: an honest comparison for product… 7 min read Webhook vs polling: the architecture decision that dete… 24 min read n8n tutorial: build your first production workflow in u… 26 min read The 9 best Zapier alternatives in 2026: an honest ranki… 21 min read Make.com tutorial: build powerful automations without c… 19 min read Automation consultant vs DIY: how to decide what is rig… 14 min read n8n Self-Hosted vs Cloud: The Complete Decision Guide (… 15 min read 5 Zapier Free Alternatives That Handle Real Production … 15 min read WhatsApp Business Automation With n8n: Build a 24/7 Cus… 17 min read Google Workspace Automation: 15 Workflows for Sheets, D… 16 min read Claude AI for Business Automation: What It Does, What I… 15 min read Airtable Automation With n8n: 10 Workflows That Make Yo… 15 min read Droven.io AI Automation Tools: Full Review and Best Alt… 14 min read Droven.io RPA and Business Automation: An Honest 2026 R… 15 min read Enterprise Workflow Automation: The Complete Guide for … 13 min read Document Workflow Automation: Software, Implementation,… 14 min read Marketing Automation Workflow: From Content Creation to… 16 min read Ad Campaign Workflow Data Model and SDR Inbound Pipelin… 14 min read ComfyUI Workflows for Business: Product Photography, Ma… 13 min read GPT-5.2 for Business Workflows and the spec-workflow-mc… 17 min read ServiceNow vs IBM BAW vs n8n: Enterprise Workflow Autom… 16 min read 9 Best Workflow Automation Tools for Small Business in …

Keep reading

More from the blog.

All articles

From audit to deployment

Experience the automation
these articles are about.

Get my free automation plan →