Blog

Networking

Where does localhost point inside Docker?

A service can work from a browser and still be unreachable from a neighboring container. The address makes sense only after you decide where the request starts.

Start with the caller

In a typical Compose setup, a container has its own network namespace. Inside that container, localhost leads back to the container itself. If an interface and a model server live in separate containers, pointing the interface at localhost sends it looking in its own room.

Use the service name

Compose provides service-name resolution on a shared network. In my local stack, the chat interface can reach the inference service at http://llama-server:8080. That name belongs to the container network. A browser on the host uses the address and port published on the host instead.

Draw the path first

I write down three things before editing the configuration. Which process makes the request? Where is the destination listening? Which network do they share? Those answers tell me whether I need the host address, a service name, or a different port.

Docker documentation on Compose networking

All posts