Full Byte Developer.

Container says Up, browser gets nothing back? Two part fix

0.0.0.0 inside the container, 127.0.0.1 on the -p flag.

Published here · 3 sources

Container says Up, browser gets nothing back?

The problem

Docker Desktop, python:3.12-slim. Server inside the container bound to 127.0.0.1. curl localhost:8000 returned "curl: (52) Empty reply from server". Chrome showed net::ERR_EMPTY_RESPONSE. Same image and port, restarted with the server bound to 0.0.0.0: HTTP 200.

Part 1: inside the container, listen on all addresses

Flask:

bash
flask run --host=0.0.0.0

Vite:

bash
vite --host 0.0.0.0

Or just --host.

Python:

bash
python -m http.server 8000 --bind 0.0.0.0

Part 2: on your machine, publish only to yourself

bash
docker run -p 127.0.0.1:5000:5000 your-image

Use your server's port on both sides: Flask 5000, Vite 5173, http.server 8000.

The rule to keep

0.0.0.0 inside the container, 127.0.0.1 on the -p flag.

Security note

By default Docker binds the forwarded port to your laptop's loopback only, so other devices on your Wi-Fi cannot use it.

Flask warns the debugger can run arbitrary code, so never expose it. My rule: never pair --host=0.0.0.0 with a plain -p 5000:5000 on a public server.

Send this to the friend whose Docker container says Up but the browser shows nothing.

Keep this guide

By Full Byte Developer

Filed under Dev tools

Questions about this guide

Why does binding to 127.0.0.1 inside fail?

The container's 127.0.0.1 is its own loopback, not your laptop's. The published port forwards to the container's network namespace, which cannot reach its loopback from outside.

Is 0.0.0.0 inside the container a security risk?

The -p 127.0.0.1:5000:5000 flag publishes only to your laptop's loopback, so other devices on your Wi-Fi cannot reach it.

Sources

  1. Flask docs: quickstartflask.palletsprojects.com

Next in this stack