A real application rarely runs in one container. A typical web app needs the app itself, a database and perhaps a cache. Starting each with a long docker run command is tedious and error-prone. Docker Compose describes all of them in one file and starts them together.
A simple compose.yaml
services:
web:
build: .
ports:
- "8000:8000"
environment:
DB_HOST: db
depends_on:
- db
db:
image: mysql:8
environment:
MYSQL_DATABASE: appdb
MYSQL_ROOT_PASSWORD: change-me
volumes:
- dbdata:/var/lib/mysql
volumes:
dbdata:
What each part does
- services: each container you want to run.
- build / image: build from your Dockerfile, or pull a ready image.
- ports: map a port on your machine to the container.
- environment: settings passed to the container.
- volumes: keep database data when containers are recreated.
Compose puts all services on one network, so the app reaches the database simply by the service name db.
Everyday commands
docker compose up -d: build and start everything in the background.docker compose ps: see what is running.docker compose logs -f web: follow the app’s logs.docker compose down: stop and remove the containers (add-vonly if you also want to delete the data).
Good habits
depends_oncontrols start order, not readiness. Add a healthcheck or retry logic so the app waits for the database.- Keep real passwords in a
.envfile that is not committed to Git. - Use Compose for development and testing; production often uses Kubernetes or a managed service.
Related: Docker basics, Docker volumes and Kubernetes for beginners.
Hands-on labs like this are part of our AWS and DevOps course in Bangalore.
Book a free demo class at our BTM Layout centre, and ask a counsellor for batch details.

Docker Images and Dockerfile Basics - ScholarLogic
[…] single containers make sense, combine several with Docker Compose, and learn how the images are deployed to […]