Published port refuses connections: you mapped 8000 but the app listens on 5000
Medium

Problem

You deployed the web service and published it with -p 8080:8000. The container is Up, docker ps shows the mapping 0.0.0.0:8080->8000/tcp, and the app logs say it's running — but every request from the host is refused:

$ curl -sS http://localhost:8080/
curl: (56) Recv failure: Connection reset by peer

The publish mapping looks right and the app is clearly up. Find out why the port is unreachable and state the fix.

Initial setup

  • webwebapp:1.4 (Flask), Up 40 minutes, 0.0.0.0:8080->8000/tcp.
  • The host cannot reach http://localhost:8080.

Example interaction

$ docker ps
# web is Up, PORTS: 0.0.0.0:8080->8000/tcp   (mapping present)

$ docker port web
8000/tcp -> 0.0.0.0:8080                      (forward targets container:8000)

$ docker exec web ss -tlnp
State  Recv-Q Send-Q Local Address:Port Peer Address:PortProcess
LISTEN 0      128          0.0.0.0:5000        0.0.0.0:*    users:(("python3",pid=1,fd=3))

The listener is on 0.0.0.0:5000 — but you forwarded to 8000.

Acceptance

You've solved it when:

  • You've shown the app listens on 0.0.0.0:5000 inside the container —
via docker exec web ss -tlnp (or netstat -tlnp) — while the published forward targets container port 8000 (docker port web). The interface is fine (0.0.0.0, not loopback); the bug is a port mismatch: Docker forwards host:8080 → container:8000, where nothing listens. NOT misdiagnosed as a loopback bind, a host firewall, or a malformed -p string (the mapping is well-formed — it just points at the wrong port).
  • You've stated the fix: align the published container port with the app's
real listen port — republish -p 8080:5000 (or make the app listen on 8000, e.g. flask run --port 8000) — and recreate the container.

Constraints

  • Tools: docker CLI only.
  • docker restart web does NOT help — the app still listens on 5000 after a
restart. The published target port is fixed at container-create time.
  • The -p 8080:8000 mapping is well-formed and binds 0.0.0.0; don't chase
a loopback bind or a host firewall. The mismatch is which container port you forwarded to.

Follow-up

  1. Why does EXPOSE 8000 (or a guessed -p …:8000) not make the app listen
on 8000? What actually determines the listening port?
  1. Why is 5000 Flask's default, and how would you have caught the mismatch
from docker port web + docker exec web ss -tlnp alone?
  1. If you instead changed the app to listen on 8000, why must you still
recreate the container rather than docker restart?
Live session
Code
SavedNo commands yet