- Start two app containers from the same image.
- Send multiple requests to the load balancer at
localhost:8080and observe how requests are distributed. - Stop one backend container while requests are being served and observe failover to the remaining container.
This lab assumes an NGINX-based load balancer is already configured to proxy requests from
localhost:8080 to the two backend app containers. For a refresher, see Introduction to NGINX.What you’ll observe
- Requests to
localhost:8080are proxied by NGINX to one of the two app containers. - NGINX performs simple load distribution between the backends (round-robin or similar, depending on config).
- If one backend stops, NGINX continues to forward requests to the remaining healthy container, keeping the service available.
Quick step-by-step
- Launch two app containers (they both use the same image).
- Confirm each container is running.
- Send multiple
curlrequests to the load balancer and observe responses from each backend. - Stop one backend and continue sending requests to observe failover.
Commands and examples
Start both containers:Commands reference
Make sure container names (e.g.,
app1, app2) match the backend upstream configuration in your NGINX proxy, and that the load balancer is listening on localhost:8080. If NGINX isn’t configured correctly, requests will not be forwarded to your containers.Troubleshooting tips
- If
curl localhost:8080returns a connection refused error, validate that NGINX is running and listening on port 8080:ss -ltnp | grep 8080ordocker ps(if NGINX is containerized).
- If responses always come from the same backend, inspect the NGINX upstream configuration to confirm the load-balancing method.
- Use
docker logs <container>to see app-specific output if you don’t get the expectedHello from ...responses.
Links and references
- Introduction to NGINX
- Docker documentation: https://docs.docker.com/
- NGINX upstream module reference: https://nginx.org/en/docs/http/ngx_http_upstream_module.html