Scaling a Multi-Container Application with Docker Compose
Your company is looking to scale its current containerized todo application to meet increasing traffic. You, as the DevOps engineer, have been tasked with converting the todo application into a Docker Compose-based setup, adding the ability to scale services and load balance requests efficiently.
Requirements
Your task is to convert the todo application into a multi-container setup using Docker Compose, where:
- The backend service can be scaled based on traffic needs.
- The MySQL database remains as a single instance for consistency purposes.
- Nginx is configured to load balance requests across multiple instances of the backend service.
You will be using the same Dockerfile from the "Building Multi-Stage Docker Images" exercise, located in the MULTI-STAGE-BUILDS
branch.
Acceptance Criteria
- Docker Compose Configuration: Use Docker Compose to define multiple services: backend, database, and a load balancer (Nginx).
- Backend Scaling: The backend service must be scalable, and scaling should be demonstrated using Docker Compose (
--scale backend=3
).
- Load Balancer Setup: Nginx must be configured to load balance requests across the backend services.
- MySQL Database: The database service should not be scaled and should remain as a single instance.
- Build Context: Use the Dockerfile from the previous exercise ("Building Multi-Stage Docker Images") to build the backend.
Resources
Possible Ways to Implement
-
Set Up Docker Compose File:
- Define services for backend, database, and nginx load balancer.
- Ensure the backend service uses the
build
context to build the image using the Dockerfile from the "Building Multi-Stage Docker Images" exercise.
-
Scaling the Backend Service:
- Use the
docker-compose.yml
file to define the backend service.
-
Load Balancing with Nginx:
- Add an Nginx service to Docker Compose that will act as a load balancer for the backend services.
- Configure Nginx to forward requests to the scaled backend instances.
-
Database Service:
- Use the official MySQL image for the database.
- Set up the database as a single instance with a persistent volume.