Docker Compose — Compose File Basics

less than 1 minute read

Welcome to Chapter 3 of the Docker Compose tutorial. This chapter teaches you the structure of a compose.yml file — the YAML syntax, the top-level keys, and how to write and run your first compose file.


Topics in This Chapter

# Topic Description
1 YAML Refresher YAML syntax essentials for compose files
2 Top-Level Keys services, volumes, networks, configs, secrets
3 Version Field The deprecated version field explained
4 First Compose File Write your first working compose.yml
5 Up and Down Starting and stopping your compose stack

What You’ll Learn

  • YAML syntax rules that matter for Compose
  • The purpose of each top-level key
  • Why the version: field is no longer needed
  • How to write a complete, runnable compose file
  • The docker compose up and docker compose down workflow

The Big Picture

┌──────────────────── compose.yml ────────────────────┐
│                                                      │
│  services:     ← Containers to run                   │
│    web:                                              │
│    db:                                               │
│                                                      │
│  volumes:      ← Persistent storage                  │
│    db-data:                                          │
│                                                      │
│  networks:     ← Custom networking                   │
│    backend:                                          │
│                                                      │
└──────────────────────────────────────────────────────┘