Module P-4·35 min read

Compose v2 workflows, profiles, overrides, and managing boot order with depends_on and health checks.

JJS
Written by Jatin Jain Saraf · Senior Software Engineer

Introduction

Running docker run manually with ten different flags (-p, -v, -e, --network) works for a single container. But a real application rarely consists of a single container.

A modern SaaS application might require:

  1. A Next.js frontend
  2. A Node.js API
  3. A PostgreSQL database
  4. A Redis cache

Typing out four complex docker run commands in the exact right order every time you want to develop locally is unsustainable.

Docker Compose is an orchestration tool that allows you to define your entire multi-container environment in a single declarative YAML file. In this module, we will explore Compose v2, managing boot order, and utilizing overrides for different environments.


The Reality of Compose V2

If you learned Docker years ago, you probably used docker-compose (with a hyphen). This was Compose V1, written in Python.

Docker has since completely rewritten Compose in Go and integrated it directly into the Docker CLI as a plugin.

  • Old Way: docker-compose up
  • New Way: docker compose up

Similarly, the configuration file is now officially named compose.yaml (though docker-compose.yml is still supported for backwards compatibility). Always prefer Compose V2 and compose.yaml for new projects.


Anatomy of a compose.yaml

A compose.yaml file defines services, networks, and volumes.

Here is a complete local development environment for a full-stack application:

yaml

What Compose does for you:

When you run docker compose up, Compose automatically:

  1. Creates a custom bridge network named my-saas-app_default.
  2. Creates the pgdata volume if it doesn't exist.
  3. Builds the api image from the ./api directory.
  4. Starts all containers and attaches them to the custom network, enabling internal DNS (the api can connect to db:5432).
  5. Streams the interleaved logs from all three containers to your terminal.

Sign in to keep reading

The rest of this module is free — sign in with Google to unlock it and track your progress.

Sign in & Register

Discussion

0

Join the discussion

Loading comments...

© 2026 Jatin Jain Saraf (JJS). All rights reserved.