How do you route traffic to multiple Compose services by hostname?
IntermediateScenarioNetworking and Compose
Answer
Situation read → One host, several web apps on port 80/443.
What I'd do → Run a reverse proxy container (Traefik or Nginx Proxy Manager/Caddy) on a shared network. With Traefik use labels:
labels:
- "traefik.http.routers.api.rule=Host(`api.example.com`)"
- "traefik.http.services.api.loadbalancer.server.port=8080"
Mount the Docker socket read-only into Traefik via a socket proxy.
Why → Auto-discovery plus automated TLS (Let's Encrypt).
Interview tip → Exposing the raw Docker socket to the proxy is a risk; use docker-socket-proxy.
More on Networking and Compose
Containers on the default bridge cannot resolve each other by name. Why, and what do you do?BeginnerHow do you expose a container only to the local host, not the internet?BeginnerDesign a Compose file for web + api + postgres + redis with correct startup ordering.IntermediateFrontend must reach the API but not the database. Segment the network.IntermediateA container needs to call a service running on the Docker host.BeginnerWhen would you use `--network host`?Intermediate