Compose Commands
Compose has its own commands for the services in a file: logs reads their output, exec runs a command in one, ps lists them, and --scale runs more copies of one service.
Count the requests in the logs
This command counts the page requests the web service logged.
docker compose -p g6proj logs web 2>&1 | grep -c "GET /"Scale a service
This command runs two copies of the web service.
docker compose -p g6proj up -d --scale web=2Example
docker compose -p g6proj up -d --scale web=2 >/dev/null
docker compose -p g6proj ps --format "{{.Name}} {{.Image}}"
docker compose -p g6proj downKey points
- Use docker compose logs to read every service's output.
- Use docker compose logs web to read one service's output.
- Use docker compose exec web sh to open a shell in the web service.
- Use docker compose ps to list the services and their state.
- Use --scale web=2 to run two copies of the web service.
In this example, Compose starts two copies of the web service. The listing shows two web containers with stable names. Two rows prove the scale flag made two copies from one service.
Note
Scaled services share the file's port mapping, so only one can publish a host port.
Try it Yourself
Edit the code, then press Run.
Running is simulated · Rust Playground
Exercise
What does docker compose up --scale web=2 do?