Module 5 Lesson 1: Introduction to Docker Compose
·DevOps

Module 5 Lesson 1: Introduction to Docker Compose

Stop typing long commands. Discover Docker Compose, the tool that allows you to define and run entire multi-container applications with a single YAML file.

Module 5 Lesson 1: Introduction to Docker Compose

Until now, we have been running single containers. But a real application usually needs multiple things:

  • A Web Frontend.
  • An API Backend.
  • A Database.
  • A Redis Cache.

Running these manually with docker run requires 4 terminal windows and a lot of typing. Docker Compose is the tool that lets you manage all of them as a single group.

1. What is Docker Compose?

Docker Compose is a tool for defining and running multi-container Docker applications. With Compose, you use a YAML file to configure your application’s services. Then, with a single command, you create and start all the services from your configuration.

The "Instruction Manual" Analogy:

  • docker run: You are the cook, performing one step at a time ("Boil water", "Add pasta").
  • docker-compose: You are the Head Chef. You provide a full recipe, and the kitchen (Docker) executes everything at once.

2. Why Use Compose?

  1. Reproducibility: You can share one docker-compose.yml file with your whole team. Everyone will have the exact same Setup (Ports, Networks, Volumes).
  2. Order: No more remembering which container needs to start first.
  3. Efficiency: Stop all services with one command (docker-compose down) and start them all with another (docker-compose up).
  4. Isolation: Compose automatically creates a dedicated network for your services so they can talk to each other without polluting your default bridge.

3. The YAML Format

Docker Compose uses YAML (Yet Another Markup Language). It is very sensitive to Indentation.

version: '3.8'           # The version of the Compose file format
services:                # Defining our "Apps"
  web:                   # A service named 'web'
    image: nginx         # Use the nginx image
    ports:               # Map ports
      - "80:80"

4. Compose vs. Orchestrators

  • Docker Compose: Best for development and single-server production. It is "Small Scale."
  • Kubernetes (K8s) / Docker Swarm: Best for managing thousands of containers across hundreds of servers. This is "Large Scale."

For 90% of developers, Docker Compose is the most important tool they will use every day.


Exercise: The Compare and Contrast

  1. Look at the docker run command you wrote for WordPress in Module 4.
  2. Now, imagine you also need a mysql database for that WordPress site.
  3. How many different flags (ports, env-vars, networks, volumes) would you need to type to get both of them talking to each other manually?
  4. Why is a "Text File" (YAML) better to store these settings than your terminal "Command History"?

Summary

Docker Compose turns "One-off commands" into "Documented Infrastructure." It is the bridge between a hobbyist running a container and a professional engineer managing an application stack.

Next Lesson: your first recipe: Writing your first docker-compose.yml.

Subscribe to our newsletter

Get the latest posts delivered right to your inbox.

Subscribe on LinkedIn