Docker Compose is a tool used to define and manage multi-container Docker applications using a YAML configuration file called docker-compose.yml.
Instead of running multiple docker run commands, Docker Compose allows you to define all services in a single file and start them with one command.
It is mainly used for:
services:
web:
image: nginx:alpine
container_name: my-nginx
ports:
- "8080:80"
volumes:
- myvolume:/usr/share/nginx/html
networks:
- mynetwork
volumes:
myvolume:
networks:
mynetwork:
Start Services: docker compose up
Start in Detached Mode: docker compose up -d
Stop Services: docker compose down
Stop and Remove Volumes: docker compose down -v
View Running Services: docker compose ps
View Logs: docker compose logs
View Live Logs: docker compose logs -f
Rebuild Services: docker compose up βbuild
Pull Latest Images: docker compose pull
Restart Services: docker compose restart
Each container is defined as a service inside docker-compose.yml.
Docker Compose automatically creates a default network. All services can communicate using service names.
Example:
If service name is web, other containers can access it using:
http://web:80
Volumes are used for:
| docker run | docker compose |
|---|---|
| Single container | Multi-container |
| Manual configuration | YAML-based configuration |
| No automatic networking | Automatic networking |
| Hard to scale | Easy scaling |
| Complex for large apps | Organized & structured |
Example stack:
All services can be defined in a single docker-compose.yml file and started using:
docker compose up -d
This simplifies deployment and environment replication.

You can scale a service directly from the command line.
Example: docker compose up -d βscale web=3
This command will start 3 containers of the service named web.
Docker automatically:
Example container names:
web-1
web-2
web-3
You can define replicas inside docker-compose.yml.
Example:
services:
web:
image: nginx:alpine
deploy:
replicas: 3
β Note:
The deploy key works properly with Docker Swarm mode.
It is not fully supported in normal docker compose standalone mode.
When multiple replicas run:
Example architecture:
Client β Nginx β web-1
web-2
web-3
β
Start and scale: docker compose up -d βscale web=3
Increase replicas: docker compose up -d βscale web=5
Check running containers: docker compose ps
Stop services: docker compose down
Docker Compose simplifies the deployment and management of multi-container applications by allowing services, networks, and volumes to be defined in a single YAML file. It enhances productivity, ensures consistency, and is widely used in modern DevOps and microservices environments.