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.
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