docker run command manually, you declare services, networks, and volumes in docker-compose.yaml and launch the entire stack with one command:
1. Recap: Running Multiple Containers with docker run
To illustrate the complexity of manual container orchestration, imagine starting four services individually:
2. Defining Services in Compose
Indocker-compose.yaml, all services and their options live under the services: key:
Every configuration change is version‐controlled in your Compose file—no more hunting down individual CLI commands.
3. Sample Voting Application Architecture
We’ll demonstrate Compose using Docker’s sample voting app, composed of:- Voting app (Python web UI): records “cats” or “dogs” votes in Redis.
- Worker (.NET): reads votes from Redis and updates PostgreSQL.
- PostgreSQL: stores persistent vote counts.
- Result app (Node.js web UI): displays tallied results from PostgreSQL.

4. Manual Stack Deployment with docker run
If images already exist on Docker Hub, you might start containers like this:
4.1 Linking Containers (Deprecated)
The--link flag creates /etc/hosts entries for cross-container DNS:
db:
Container links are deprecated. Instead, use user‐defined networks as shown in the next sections.
5. From docker run to docker-compose.yaml
Convert your verified docker run commands into a Compose file:
6. Building Local Images in Compose
If your service images are built locally, specify abuild: context instead of image::
7. Compose File Versions Compared
Different Compose versions introduce new features and schemas. Refer to this summary:Examples
Version 1
Version 2
Version 3
8. Defining Custom Networks
By default, Compose creates a single bridge network. You can isolate traffic with multiple networks:
Next Steps
Now that you’ve mastered service definitions, version schemas, and custom networks, try creating and running your owndocker-compose.yaml configurations in the exercises below.