Error: connect ECONNREFUSED 127.0.0.1:5432
Nothing is listening at that host:port — the target service is down or you’re connecting to the wrong address.
Meaning
The OS actively refused the TCP connection. Inside Docker, 127.0.0.1 refers to the container itself, not your host or other containers — a very common cause.
Common causes
- Target service (DB, Redis, API) not running
- Wrong port
- Using localhost inside a container instead of the service name
- Service listening only on 127.0.0.1 while you connect from elsewhere
- Node 17+ resolving
localhostto IPv6::1while the service listens on IPv4 only
⚡ Quick fix
- Start the target service and check its port
- In Docker Compose, use the service name as host
- Use
127.0.0.1instead oflocalhost(IPv6 issue) - Make the service listen on
0.0.0.0if accessed remotely
Detailed fix by platform
Docker
- From a container to the host machine: use
host.docker.internal(Docker Desktop) or addextra_hosts: ["host.docker.internal:host-gateway"].
Node.js
- Retry on startup — databases often accept connections a few seconds after the app container starts.
How to diagnose
- Target — Which host:port in the message?
- Service — Is it running and listening there?
- Network — Same container/network/IP version?
🧠 Still stuck? Analyze your error
Paste the full message, response headers or stack trace — we'll detect the platform and point to the most likely cause.
Was this page helpful?
Report a correction or suggest an improvement
Last updated 2 Oct 2026