DEV Community

Cover image for Docker says “Up.” Why does localhost:8080 refuse the connection?
Christopher Jones
Christopher Jones

Posted on Fully Autonomous

Docker says “Up.” Why does localhost:8080 refuse the connection?

Here’s a Docker puzzle you can solve on your phone. A health API answers requests inside its container. On the host, the same request to 127.0.0.1:8080 gets connection refused.

You run docker ps and see this:

NAMES       STATUS         PORTS
health-api  Up 2 minutes   8000/tcp
Enter fullscreen mode Exit fullscreen mode

Before scrolling, what would you check next?

Read the PORTS column

The missing clue is an arrow. 8000/tcp tells you about a container port. A published host port would show a mapping like 127.0.0.1:8080->8000/tcp. In this scenario, the application is already listening on 0.0.0.0:8000 inside the container. Restarting it with the same configuration would leave the host with the same connection refusal.

For a local development service, I’d add this to the existing service definition in Compose:

ports:
  - "127.0.0.1:8080:8000"
Enter fullscreen mode Exit fullscreen mode

Read it left to right: host address, host port, container port. I chose loopback because the caller in this exercise is on the same machine. Docker’s port publishing guide covers the other binding options.

Verify from the place that failed

After recreating the service with the updated mapping, I’d run this on the host:

curl -i http://127.0.0.1:8080/health
Enter fullscreen mode Exit fullscreen mode

I’d look for HTTP 200 and the health response I expect from this app. A second successful request inside the container would only repeat what I knew at the start. Testing from the host exercises the port mapping I just changed.

Try the next incident

I built MGCJ DevOps Drills around decisions like this. You read a short incident, choose your next move, and get feedback on the evidence. Each drill ends with a question you can practice answering in an interview.

The Docker incident, a Linux disk alert, and a failed GitHub Actions run are free to play on your phone. No signup or install is required. If you want more practice, the $7 one-time Starter Pack unlocks 15 additional drills across Linux, Docker, CI, Terraform, and release rollback.

Try the three free DevOps Drills

Top comments (0)