Application Servers

To build a load balancer setup, we first need some application servers to balance traffic across! We’ll use Caddy, an awesome modern open-source web server written in Go. (Nginx and Apache are other popular alternatives).

Setting Up Test Servers

We’ll set up two servers that serve slightly different HTML pages so we can see load balancing in action.

  1. Create an index1.html file on your host machine:

    <html>
      <body>
        <h1>Hello from server 1</h1>
      </body>
    </html>
  2. Create an index2.html file on your host machine:

    <html>
      <body>
        <h1>Hello from server 2</h1>
      </body>
    </html>
  3. Run the first container on port 8881:

    docker pull caddy
    docker run -d -p 8881:80 -v $PWD/index1.html:/usr/share/caddy/index.html caddy
  4. Run the second container on port 8882:

    docker run -d -p 8882:80 -v $PWD/index2.html:/usr/share/caddy/index.html caddy

If you navigate to localhost:8881 in your browser, you’ll see “Hello from server 1”. If you navigate to localhost:8882, you’ll see “Hello from server 2”.