🐳 Docker Learning Hub
Lesson 6 • Compose and multi-container app setup
Lesson 6

Docker Compose and multi-container setup

This page explains how to manage app, database, ports, networks, and volumes together in one Compose file instead of running many separate Docker commands.

Main idea

Docker Compose lets you define a multi-container setup in one YAML file.

Main use

It is useful when your project has multiple services like an app, database, and supporting containers.

Main result

You can start the whole stack with one command instead of remembering many long Docker commands.

Without Compose

Build image manually
Create network manually
Create volume manually
Run each container separately

With Compose

Define everything in one file
Run `docker compose up`
All services start together

Basic Compose structure

services: app: image: my-app db: image: mysql:8

In Compose, each major part of your system is defined as a service.

Common things Compose can define

  • services
  • ports
  • volumes
  • networks
  • environment variables
  • startup relationships

Beginner Compose example

services: app: build: . ports: - "3000:3000" depends_on: - db db: image: mysql:8 environment: MYSQL_ROOT_PASSWORD: rootpass volumes: - db_data:/var/lib/mysql volumes: db_data:
This file says: build the app from the current folder, start a MySQL database, expose the app on port 3000, and keep database data inside a named volume.

Important Compose commands

docker compose up docker compose up -d docker compose up --build docker compose down docker compose ps docker compose logs

What those commands do

  • up starts the services
  • up -d starts them in the background
  • up --build rebuilds before starting
  • down stops and removes the started containers
  • ps shows running services
  • logs shows service logs

Why service names matter in Compose

Inside Compose, services can usually reach each other by service name. If your database service is called db, your app can often use db as the host.

Common beginner mistake

depends_on helps control start order, but it does not guarantee that a database is fully ready to accept connections.

What you learned in Lesson 6

Compose simplifies multi-container work
You do not have to manually manage every container with separate long commands.
One YAML file defines the stack
Services, ports, volumes, and environment details can live together in one place.
Compose builds on earlier lessons
It combines images, containers, volumes, and networks into one practical workflow.
Compose is a big step toward real projects
It reflects how many real local development environments are managed.

Next page: Lesson 7 explains how to pass app settings into containers using environment variables.