The main Docker Compose commands are docker compose up -d (create and start every service in the background), docker compose down (stop and remove containers and networks, keeping volumes), docker compose ps (list services), docker compose logs -f (follow output), docker compose exec <service> bash (open a shell), docker compose build (build images) and docker compose restart. Type it with a space: the hyphenated docker-compose is the old V1 binary. This Docker Compose commands cheat sheet covers 12 essential commands and two docker-compose.yml examples. The PDF is free. Drop your email and it lands in your inbox.
Docker Compose Commands Cheat Sheet: docker-compose Command Not Found
If you see docker-compose: command not found or docker: 'compose' is not a docker command, you’re mixing the two versions. docker-compose (hyphen) is Compose V1, a separate standalone binary that’s no longer maintained. docker compose (space) is Compose V2, a plugin inside the Docker CLI.

Fix on Ubuntu or Debian, per Docker’s Compose install guide, with Docker’s apt repository already set up:
sudo apt-get update
sudo apt-get install docker-compose-plugin
docker compose version
On macOS or Windows, Docker Desktop includes the plugin. Every command below uses the V2 syntax.
A Real docker-compose.yml, Line by Line
Compose files are written in YAML. To see when YAML is a better fit than JSON or XML, read JSON vs XML vs YAML.
services:
web:
build: .
ports:
- "8080:80"
environment:
DB_HOST: db
depends_on:
- db
db:
image: mysql:8.4
volumes:
- mysql-data:/var/lib/mysql
volumes:
mysql-data:
| Field | What it does |
|---|---|
services | Defines each part of the app: web, db, cache |
build | Builds an image from a local Dockerfile |
image | Uses a ready-made image such as mysql:8.4 |
ports | Publishes a container port: "8080:80" is host 8080 to container 80 |
volumes | Keeps data outside the container so it survives a rebuild |
Compose sets up one network for your app, and each service is reachable by its service name, per Docker’s networking docs. So web reaches the database at db:3306, using the container port, not localhost:3306.

Docker Compose Core Commands: up, down, ps, logs
| Command | What it does |
|---|---|
docker compose up | Creates and starts every service |
docker compose up -d | Same, detached, so your terminal stays free |
docker compose down | Stops and removes containers and networks |
docker compose ps | Lists the stack’s containers |
docker compose logs | Shows output from all services |
docker compose logs -f | Follows the logs live |
docker compose down keeps named volumes and images. Add -v and it also removes named and anonymous volumes, which deletes your database data. That’s per Docker’s down reference.

Docker Compose Build, Exec and Cleanup Commands
| Command | What it does |
|---|---|
docker compose build | Builds or rebuilds service images |
docker compose up --build | Rebuilds, then starts |
docker compose exec web bash | Opens a shell in the running web service |
docker compose restart | Restarts services without rebuilding |
docker compose pull | Pulls newer images for image-based services |
docker compose stop | Stops services without removing them |
docker compose config | Validates the file and prints the merged configuration |
Docker’s CLI reference lists 36 top-level docker compose subcommands. These are the ones you’ll use daily.
Docker Compose depends_on vs healthcheck
depends_on controls start order, but per Docker’s startup order guide, Compose doesn’t wait until a container is ready, only until it’s running. A database can be running seconds before it accepts connections.

db:
image: mysql:8.4
healthcheck:
test: ["CMD", "mysqladmin", "ping", "-h", "localhost"]
interval: 10s
retries: 5
web:
depends_on:
db:
condition: service_healthy
With a healthcheck on db and condition: service_healthy on web, Compose waits for the database to pass its check before starting web.
Docker Compose vs docker run vs Kubernetes
| Tool | What it does | Best for |
|---|---|---|
docker run | One container, every flag typed by hand | Quick one-offs |
| Docker Compose | A multi-container app in one YAML file | Local development, demos, small deployments |
| Kubernetes | Containers across a cluster of machines | Production at scale |
Compose runs a stack on one machine. It isn’t a Kubernetes replacement. When you move to Kubernetes, start with these kubectl commands. For the Dockerfile side, see the Dockerfile Commands Cheat Sheet. For plain docker commands, see the Docker Commands Cheat Sheet.
What’s Inside the Docker Compose Commands Cheat Sheet PDF
- 12 essential Docker Compose commands in one table
- Two real docker-compose.yaml examples, ready to copy
- The depends_on vs healthcheck explanation
- A quick reference for environment variables, networking and volumes
Who It’s For
- Anyone new to multi-container apps, from zero
- Developers who run Compose daily but forget the healthcheck syntax or whether
downdeletes volumes - DevOps learners
No questions yet. Ask the first one.