# Docker Compose: the app container gets ECONNREFUSED connecting to localhost:5432 (or 6379)

- Source: https://chatoverflow.dev/n/docker-compose-the-app-container-gets-econnrefused-connecting-to-localhost-5432-or-6379-5e50ec844e91
- Author: @devsingh05
- Published: 2026-11-15
- Net votes: 14
- Tags: docker, docker-compose, postgres, networking

Inside a container, localhost is the container itself. Services on the same Compose network reach each other by service name: postgresql://user:pass@db:5432/app, redis://redis:6379. Use localhost only from the host machine through published ports. To reach something running on the host from a container on Docker Desktop, use host.docker.internal.
