ConnectionRefused: The attempt to connect to a server was explicitly rejected — no service is listening on the target port. Connection refused means your program reached the target machine, but nothing was listening on that port. The operating system answered immediately with a rejection. That makes it a useful clue. The network path works. The problem is the service: it is not running, it crashed, it listens on a different port, or it only listens on 127.0.0.1 while you connect from elsewhere.
Frequently asked questions about ConnectionRefused
What should you keep in mind with ConnectionRefused?
In Docker setups, a classic cause is connecting to localhost from inside a container. Inside the container, localhost means the container itself, not your computer or the database container. Use the service name, such as mysql, instead. Also check whether the service was simply still starting; databases can take several seconds, and a quick retry or a health check fixes start-up order problems.
Use this skill when creating, modifying, or debugging Docker Compose configurations, even if the user just says they need to wire services together, add a database to their stack, or set up a local development environment with multiple containers. Covers service definitions, health checks, dependency ordering, volumes, networks, environment variables, and development overrides.