• Explore
  • About Us
  • Log In
  • Get Started
  • Explore
  • About Us
  • Log In
  • Get Started

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:

  1. The backend service can be scaled based on traffic needs.
  2. The MySQL database remains as a single instance for consistency purposes.
  3. 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

  1. Docker Compose Configuration: Use Docker Compose to define multiple services: backend, database, and a load balancer (Nginx).
  2. Backend Scaling: The backend service must be scalable, and scaling should be demonstrated using Docker Compose (--scale backend=3).
  3. Load Balancer Setup: Nginx must be configured to load balance requests across the backend services.
  4. MySQL Database: The database service should not be scaled and should remain as a single instance.
  5. Build Context: Use the Dockerfile from the previous exercise ("Building Multi-Stage Docker Images") to build the backend.

Resources

  • Docker Compose Documentation
  • Project Repository: Docker Mastery Project Branch: MULTI-STAGE-BUILDS

Possible Ways to Implement

  1. 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.
  2. Scaling the Backend Service:

    • Use the docker-compose.yml file to define the backend service.
  3. 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.
  4. Database Service:

    • Use the official MySQL image for the database.
    • Set up the database as a single instance with a persistent volume.

    Mastering Docker

    Unlock All Exercises

  • Getting Started
    • Important - Please Read
  • Introduction to Docker
    • Containerizing a Legacy Application
    • Building Minimal Docker Images
    • Diagnosing a Broken Container
  • Docker Images and Registries
    • Building Multi-Stage Docker Images
    • Pushing Images to a Private Registry
    • Automating Image Builds with Docker Hub
    • Versioning and Tagging Docker Images
    • Securing Docker Images with Trusted Registries
  • Docker Networking
    • Isolating Services with Docker Networks
    • Connecting Microservices Across Networks
    • Debugging Network Issues in Containers
  • Data Persistence
    • Migrating Data with Docker Volumes
    • Data Backup and Recovery in Containers
    • Handling Sensitive Data with Docker Secrets
  • Docker Compose
    • Scaling a Multi-Container Application
    • Handling Environment Variations
  • Docker Security
    • TLS Authentication for Docker Daemon
    • Implementing User Namespaces
    • Monitoring and Responding to Security Threats
    • Securing HTTP APIs with TLS in Containers
  • Advanced Docker Usage
    • Integrating Docker in CI/CD Pipelines
    • Monitoring and Logging with Docker
    • Docker Resource Management
  • Winding Up
    • Final Notes