Published ports and container networks
Host publication maps a host interface and port to a container port. Containers on a user-defined bridge network can resolve each other by name. localhost inside a container refers to that container, not another service or automatically the host. Exposing metadata is not the same as publishing a host port. For example, a frontend calls http://api:8080 on the shared network, while a host browser uses a published localhost port.
A frontend calls http://api:8080 on the shared network, while a host browser uses a published localhost port.
A host browser connects to localhost:8200, which Docker forwards to a container's port 80. Inside that container, localhost still identifies the container's own network namespace, not the host browser or a second container. Two containers on a suitable user-defined network can instead communicate through their configured names and container ports.
A published port maps host reachability to a container port. A bridge network connects participating containers. DNS discovery translates service or container names into reachable addresses within its supported scope. EXPOSE documents an intended port but does not itself publish it to the host. Diagnose source location, destination address, listening interface, and port mapping separately. A server listening only on container-local loopback may not accept forwarded traffic through its network interface. Publishing on every host interface can expose a development service to other machines, so use explicit localhost bindings for local beginner exercises.
A frontend calls http://api:8080 on the shared network, while a host browser uses a published localhost port.
Do not overlook this operational distinction: Exposing metadata is not the same as publishing a host port.