Skip to content

Latest commit

 

History

History
77 lines (51 loc) · 1.9 KB

README.md

File metadata and controls

77 lines (51 loc) · 1.9 KB

Docker Load Balancer Example

This project demonstrates how to set up a simple load-balanced application using Docker and Nginx. The application is built with Node.js and serves HTTP requests, while Nginx acts as a load balancer to distribute incoming traffic across multiple instances of the application.

Project Structure

docker-loadbalancer-example
├── app
│   ├── src
│   │   └── index.js
│   ├── Dockerfile
│   └── package.json
├── nginx
│   ├── Dockerfile
│   └── nginx.conf
├── docker-compose.yml
└── README.md

Getting Started

Prerequisites

  • Docker
  • Docker Compose

Building the Application

To build the application and Nginx images, run the following command in the root of the project:

docker-compose build

Running the Application

To start the application with load balancing, use the following command:

docker-compose up

This command will start the application and Nginx, with Nginx configured to distribute requests to multiple instances of the application.

Accessing the Application

Once the application is running, you can access it by navigating to http://localhost in your web browser. Nginx will load balance the requests to the available application instances.

Scaling the Application

To scale the number of application instances, you can modify the docker-compose.yml file. Look for the replicas setting under the application service and change the number to your desired scale. For example:

deploy:
  replicas: 3

After modifying the file, run the following command to apply the changes:

docker-compose up -d --scale app=3

This will start three instances of the application.

Stopping the Application

To stop the application and remove the containers, run:

docker-compose down

License

This project is licensed under the MIT License.