Main idea
Docker Compose lets you define a multi-container setup in one YAML file.
This page explains how to manage app, database, ports, networks, and volumes together in one Compose file instead of running many separate Docker commands.
Docker Compose lets you define a multi-container setup in one YAML file.
It is useful when your project has multiple services like an app, database, and supporting containers.
You can start the whole stack with one command instead of remembering many long Docker commands.
services:
app:
image: my-app
db:
image: mysql:8
In Compose, each major part of your system is defined as a service.
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:
docker compose up
docker compose up -d
docker compose up --build
docker compose down
docker compose ps
docker compose logs
up starts the servicesup -d starts them in the backgroundup --build rebuilds before startingdown stops and removes the started containersps shows running serviceslogs shows service logsInside 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.
depends_on helps control start order, but it does not guarantee that a database is fully ready to accept connections.
Next page: Lesson 7 explains how to pass app settings into containers using environment variables.