What you will learn
- Write a compose file
- Manage service dependencies
- Use environments
New to this? Start here
The basics, in plain English
Real apps have several containers at once: a web server, a database, a cache. Docker Compose lets you describe the whole set in one file and start them all together with a single command.
- Docker Compose
- A tool to define and run multiple containers together from one file.
- compose file
- A YAML file listing each service, its image, ports, and settings.
- Service
- One container definition inside the compose file, like “web” or “db”.
- YAML
- A simple, indented text format used for configuration files.
- up / down
- Commands that start the whole stack (up) or stop and remove it (down).
01
One file, many services
Compose describes services, networks, and volumes in YAML. docker compose up brings the whole stack online.
Try it yourself
yaml
services:↳Top-level list of containers Compose will run. web:↳A service named “web”. build: .↳Build its image from the Dockerfile in this folder. ports: ["8080:80"]↳Expose container port 80 as 8080 on your machine. depends_on: [db]↳Start the db service before this one. db:↳A second service named “db”. image: postgres:16↳Use the prebuilt Postgres 16 image.↳ lines explain what each command does — only the commands get copied
Finished this topic?
Mark it done to earn 100 XP and keep your streak alive.