Docker Published Port Unreachable? Check the App Bind Address
Contents
If docker port lists a mapping and an HTTP request to 127.0.0.1 inside the container works, try the container’s bridge IP from the same container. If that request fails and the app listens only on loopback, change the app’s bind address to 0.0.0.0. Keep the host side of the port mapping on 127.0.0.1 when you only need host-local access.
The two addresses are set independently. In -p 127.0.0.1:8080:3000, Docker publishes host port 8080 on host loopback and forwards to container port 3000. The app’s own configuration determines which addresses accept connections on port 3000 inside the container. When the listener binds only to container loopback, it can answer an internal localhost check while refusing traffic addressed to its bridge IP. On the default bridge, Docker forwards published-port traffic to that bridge IP, as described in Docker’s port publishing guide.
Run the same three probes against both listeners
This Bash fixture uses Docker’s default bridge and runs a small Node HTTP server twice. It keeps the same publication rule and lets Docker assign a free host port for each run. The probes use IPv4 throughout. Run it from a host that can reach the Docker engine’s published loopback ports.
#!/usr/bin/env bashset -eu
probe_bind() ( cid=$(docker run --rm -d -p 127.0.0.1::3000 node:26-alpine \ node -e 'require("node:http").createServer((req, res) => res.end("ok\n")).listen(3000, process.argv[1])' "$1") trap 'docker stop -t 1 "$cid" >/dev/null' EXIT
mapping=$(docker port "$cid" 3000/tcp) ip=$(docker inspect --format '{{.NetworkSettings.Networks.bridge.IPAddress}}' "$cid") printf '\nlistener=%s published=%s\n' "$1" "$mapping"
for attempt in 1 2 3 4 5; do if docker exec "$cid" wget -q -T 2 -O /dev/null http://127.0.0.1:3000/ 2>/dev/null; then break fi sleep 1 done
printf 'container loopback: ' docker exec "$cid" wget -q -T 2 -O - http://127.0.0.1:3000/ printf 'container bridge IP: ' docker exec "$cid" wget -q -T 2 -O - "http://$ip:3000/" || printf 'failed\n' printf 'host published port: ' curl -fs --noproxy '*' --max-time 3 "http://$mapping/" || printf 'failed\n')
probe_bind 127.0.0.1probe_bind 0.0.0.0On Docker Engine 28.4.0 (Linux arm64 via Colima 0.10.1 on macOS) with Node.js 26.13.1, both runs reported a published address of the form 127.0.0.1:<port>. The probes returned the following results.
| App listener | Container loopback | Container bridge IP | Host published port |
|---|---|---|---|
127.0.0.1:3000 | ok | Connection refused | Failed |
0.0.0.0:3000 | ok | ok | ok |
The bridge-IP probe runs entirely inside the container. When it fails, as in the first run, the app is refusing connections on the address Docker forwards to, so fix the listener before you investigate host forwarding. If that probe succeeds but the host probe still fails, check the host address and port reported by docker port, the Docker context, and the host’s forwarding path.
Apply the change to your app
Set the listen host in the application or framework configuration and restart the app with that configuration. For Node.js, pass '0.0.0.0' as the host to server.listen. In Compose, keep the host side local with ports: ["127.0.0.1:8080:3000"]. If the listen host comes from a changed Compose environment value, recreate the container so it receives the new value. Then repeat the request from the host.
Check the engine version before relying on the loopback host binding. Docker’s documentation warns that on releases older than 28.0.0, hosts on the same layer-2 segment can reach ports published to localhost.
References: Docker port publishing and mapping · Node.js server.listen