Compose proxy topology
Trace a request across the Compose network
The host port is the entry point for the browser. Inside a Compose network, containers address each other using service DNS names and container ports. Our two small app services return distinct labels. The edge listens on 8080 inside its container and is published as 127.0.0.1:18080 on the host. The backends have no host port mappings. A loopback binding is appropriate for this lab, not a public deployment design; verify engine networking behavior and firewall on the selected platform. Containers on the shared network can still reach the backends.
Host 127.0.0.1:18080 → edge:8080 /catalog/ → catalog:8080 /orders/ → orders:8080Route by service name, not localhost
Within the edge container, localhost refers to that container, not the host or catalog service. Use catalog:8080 and orders:8080 on the private project network. Each location below strips its prefix because proxy_pass includes the slash URI. Set a deliberate Host policy; here each app is a synthetic fixed service and the service name is sent. The apps expose a root marker and a separate health endpoint. A request to an unmatched path should be rejected, not silently sent to the wrong service.
location /catalog/ { proxy_pass http://catalog:8080/; proxy_set_header Host catalog;}location /orders/ { proxy_pass http://orders:8080/; proxy_set_header Host orders;}location / { return 404; }Start dependencies and verify readiness
A running process is not necessarily ready. Compose can wait for a dependency healthcheck when configured with service_healthy. A healthcheck must use a tool actually present in the image; this lab requires a reviewed Alpine image with working wget. The edge health endpoint proves only its own listener works; application route tests verify upstream reachability. Compose startup conditions do not continuously reconcile dependent services or promise recovery from all failures.
depends_on: catalog: condition: service_healthy orders: condition: service_healthyAccount for replacement and DNS caching
When Compose replaces a service, its IP can change while its service name stays the same. A simple literal proxy_pass hostname is resolved at configuration loading; do not assume ongoing DNS refresh. This lab uses a planned edge recreation after replacing a backend, avoiding any claim of seamless discovery. For dynamic upstream resolution, consult the exact Nginx release and resolver configuration (upstream resolve became available in Open Source 1.27.3). Validate both routes and the expected 404 after changes; do not rely on one green healthcheck.
curl -fsS http://127.0.0.1:18080/catalog/curl -fsS http://127.0.0.1:18080/orders/curl -sS -o /dev/null -w "%{http_code}\n" http://127.0.0.1:18080/missingUse the Chapter 48 manual practice and lab. Snippets are illustrative; Docker and image execution were not available during authoring. The fixture requires an approved isolated Docker environment and a locally preloaded verified digest.
Check Your Understanding
Solidify your learning with the interactive assessment directly below this lesson.
Concept Quiz & Questions
Compose proxy topology
Assess decisions from the lesson and original lab.
Which address reaches catalog from edge?
What URI reaches catalog for /catalog/ with the shown proxy_pass?
What does omitting backend ports prevent?
What does service_healthy provide?
Why might a simple proxy hostname become stale?