Skip to main content

Command Palette

Search for a command to run...

Module 6: Multi-Container Applications

Updated
2 min readView as Markdown

🔹 Why Multi-Container Setups Are Needed

In real-world applications, one container is rarely enough.

  • A web app might need a database.

  • A backend service might rely on a cache like Redis.

  • Splitting services makes applications more scalable, modular, and easier to maintain.

Instead of packing everything into one container, we run multiple containers that work together.


🔹 Linking Services Manually

Before Docker Compose, containers were linked manually:

# Run MySQL container
docker run -d --name mysql-db -e MYSQL_ROOT_PASSWORD=root mysql:8.0

# Run WordPress container linked to MySQL
docker run -d --name wordpress --link mysql-db:mysql -p 8080:80 wordpress

👉 But this approach doesn’t scale well for large projects.


🔹 Writing a Simple docker-compose.yml

docker-compose makes managing multi-container applications easy.
Here’s an example docker-compose.yml:

version: '3.8'
services:
  db:
    image: mysql:8.0
    restart: always
    environment:
      MYSQL_DATABASE: wordpress
      MYSQL_USER: wp_user
      MYSQL_PASSWORD: wp_pass
      MYSQL_ROOT_PASSWORD: root
    volumes:
      - db_data:/var/lib/mysql

  wordpress:
    image: wordpress:latest
    restart: always
    ports:
      - "8080:80"
    environment:
      WORDPRESS_DB_HOST: db:3306
      WORDPRESS_DB_USER: wp_user
      WORDPRESS_DB_PASSWORD: wp_pass
      WORDPRESS_DB_NAME: wordpress
    depends_on:
      - db

volumes:
  db_data:

🔹 Example: WordPress + MySQL Using Docker Compose

  1. Save the above YAML file as docker-compose.yml.

  2. Run:

     docker-compose up -d
    
  3. Open browser → http://localhost:8080

  4. You’ll see WordPress setup screen, connected to MySQL automatically.


Key Benefits of Multi-Container Apps

  • Clear separation of concerns

  • Easier scaling of individual services

  • Faster debugging & upgrades

  • Production-ready with minimal changes


Mastering Docker: The Complete Guide

Part 6 of 14

This series takes you on a journey from Docker basics to advanced real-world applications. You’ll learn everything from running your first container, building images, and managing networks, to multi-container setups, CI/CD pipelines.

Up next

Module 7: Multi-Stage Docker Builds

🔹 What is a Multi-Stage Build? A multi-stage build in Docker allows you to use multiple FROM statements in a single Dockerfile. Each stage can focus on a different task—for example, building source code in one stage and creating a lightweight final ...

More from this blog

D

DevOps Launchpad - Learn DevOps,Cloud, and Kubernetes

26 posts