Skip to main content
This lab demonstrates running a small app in two backend containers behind an NGINX load balancer. You will:
  • Start two app containers from the same image.
  • Send multiple requests to the load balancer at localhost:8080 and 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:8080 are 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

  1. Launch two app containers (they both use the same image).
  2. Confirm each container is running.
  3. Send multiple curl requests to the load balancer and observe responses from each backend.
  4. Stop one backend and continue sending requests to observe failover.

Commands and examples

Start both containers:
Send requests to the load balancer on port 8080:
Simulate failover by stopping one backend while requests are ongoing:

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:8080 returns a connection refused error, validate that NGINX is running and listening on port 8080:
    • ss -ltnp | grep 8080 or docker 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 expected Hello from ... responses.
This exercise shows how NGINX maintains availability by routing traffic to the remaining healthy backend when one container is taken down.

Watch Video

Practice Lab