Interview Prep/Docker/Networking and Compose

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.

All Docker questions Roadmap: Docker & containers

More on Networking and Compose