App works in container-to-container but curl localhost:PORT from the host is refused.
The service binds to 127.0.0.1 inside its container (not 0.0.0.0), so the published port has nothing behind it.
grep -R "127.0.0.1\|localhost" *.env *.ymlcommand: --host 0.0.0.0 # example for ClickHousedocker compose ps # look at published ports columnContainers are not laptops: always bind 0.0.0.0 and publish ports explicitly.
Full walkthrough: Docker Compose Connection Refused on Localhost: The Real Reason on the NinjaOps blog.
Spinning up a fresh box to reproduce or escape this error?
Managed cloud hostingNinjaOps publishes free engineering guides. Some outbound links are affiliate links: they cost you nothing and support the site.
Last reviewed 2026-10-02 · NinjaOps SEO grid · DevOps blog