Interview Prep/Docker/Networking and Compose

Load balance three replicas on a single Docker host without Kubernetes.

IntermediateScenarioNetworking and Compose
Answer

Situation read → Compose deploy.replicas works with docker compose up --scale.

What I'd do →

docker compose up -d --scale api=3

Do not publish a fixed host port on the scaled service; put nginx/Traefik in front, which resolves api via Docker DNS (round-robin across A records).

Why → Docker's embedded DNS returns all replica IPs.

Interview tip → Nginx caches DNS at start; use resolver 127.0.0.11 with a variable in proxy_pass.

All Docker questions Roadmap: Docker & containers

More on Networking and Compose