5.1: Why Docker Compose? (From script to description)

Introduction

So far, we’ve deployed our containers manually using docker run. This is great for understanding how everything works, but it quickly gets complicated once you have multiple containers to manage.

Imagine your PHP/MariaDB stack with Redis, an Nginx container, and Traefik… With docker run, you’d have to run a dozen commands and remember the --network, -v, -e, etc.

That’s whereDockerCompose comes in.

The idea: from script to description

  • With Compose, you describe your stack in a YAML file (docker-compose.yml).
  • Each service (web, database, cache…) is defined with:
    • the image to use
    • volumes and networks
    • environment variables
    • exposed ports
  • Benefits :
    • Simple deployment:docker-compose up -d runs everything.
    • Maintainability: no need to remember 10 complicated commands.
    • Portability: the YAML file can be shared or versioned.

Analogy:Docker run = writing each command by hand.Docker Compose = providing a construction plan thatDocker it follows automatically.

Installation

Windows & Mac

  • If you useDocker Desktop, Compose is already included.
  • Check the version:
docker compose version

Linux

  • On Linux,Docker Compose is now available via the official pluginDocker.
  • Make sure you have the latest version ofDockerEngine and enable the plugin:
docker compose version
  • If you see an error message, install the plugin:
sudo apt update
sudo apt install docker-compose-plugin
docker compose version

The modern syntax isdocker compose (without a hyphen). The traditional commanddocker-compose is deprecated.


📌 Key takeaway

  • Docker Compose makes it easier to manage multi-container stacks.
  • It transforms your repetitive commands into a structured declaration.
  • Windows and Mac: Compose is already built intoDocker Desktop.
  • docker composeLinux : Use the officialDockerCompose plugin and the syntax.