Black Friday: 50% off every workbook with code . Ends Nov 30, 23:59 ET. Buy Now

Last day: 50% off every workbook ends tonight at 23:59 ET. Code Buy Now

Skip to main content
intermediate Free with email

Docker Compose Commands Cheat Sheet: 12 Commands Explained

Reviewed 2026-02-04

Direct answer
The main Docker Compose commands are docker compose up -d (create and start every service), docker compose down (stop and remove containers and networks, keeping volumes), docker compose ps, docker compose logs -f, docker compose exec bash, docker compose build and docker compose restart. Use a space: the hyphenated docker-compose is the old V1 binary.

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.

Docker Compose commands: docker-compose with a hyphen is the old V1 binary, docker compose with a space is the V2 plugin, check with docker compose version
The command not found error usually means you typed the old hyphenated V1 command.

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:
FieldWhat it does
servicesDefines each part of the app: web, db, cache
buildBuilds an image from a local Dockerfile
imageUses a ready-made image such as mysql:8.4
portsPublishes a container port: "8080:80" is host 8080 to container 80
volumesKeeps 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 network: a web service reaches the database at db:3306 by service name, while localhost:3306 points at the web container itself
Inside Compose, use the service name and the container port. localhost points at the container itself.

Docker Compose Core Commands: up, down, ps, logs

CommandWhat it does
docker compose upCreates and starts every service
docker compose up -dSame, detached, so your terminal stays free
docker compose downStops and removes containers and networks
docker compose psLists the stack’s containers
docker compose logsShows output from all services
docker compose logs -fFollows 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 down compared: docker compose down removes containers and networks but keeps volumes, down -v also removes named and anonymous volumes
docker compose down keeps your data. Adding -v deletes it.

Docker Compose Build, Exec and Cleanup Commands

CommandWhat it does
docker compose buildBuilds or rebuilds service images
docker compose up --buildRebuilds, then starts
docker compose exec web bashOpens a shell in the running web service
docker compose restartRestarts services without rebuilding
docker compose pullPulls newer images for image-based services
docker compose stopStops services without removing them
docker compose configValidates 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.

Docker Compose startup: depends_on waits only until a container is running, condition service_healthy waits until its healthcheck passes
depends_on waits until a service is running. service_healthy waits until it’s ready.
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

ToolWhat it doesBest for
docker runOne container, every flag typed by handQuick one-offs
Docker ComposeA multi-container app in one YAML fileLocal development, demos, small deployments
KubernetesContainers across a cluster of machinesProduction 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 down deletes volumes
  • DevOps learners

Frequently asked questions

What are the basic Docker Compose commands?
docker compose up -d starts the stack, docker compose ps lists it, docker compose logs -f follows output, docker compose exec opens a shell, and docker compose down stops and removes it.
Why would you use Docker Compose?
It replaces a list of manual docker run commands with one YAML file and one command. You define the web app, database and cache once, then start them together with docker compose up.
Are Docker and Docker Compose the same?
No. Docker builds and runs individual containers. Compose sits on top and manages several containers as one app from a YAML file. You still need Docker installed.
Will docker compose down delete my volumes?
No, not by default. It removes containers and networks and keeps volumes and images. Add -v to remove volumes too, which deletes the data in them.
What does depends_on do in Docker Compose?
It sets start order only. Compose waits until the dependency is running, not ready. Add a healthcheck to it and condition: service_healthy on the dependent service to wait for readiness.
What's the difference between docker-compose and docker compose?
docker-compose is the old standalone V1 binary. docker compose is the V2 plugin built into the Docker CLI. Install docker-compose-plugin and use the space.
Is Docker Compose the same as Kubernetes?
No. Compose runs a multi-container app on one machine. Kubernetes orchestrates containers across a cluster for production at scale.

Questions about this PDF

No questions yet. Ask the first one.

Ask a question

Your email address won't be published. We review every question before it appears. How we handle your data. Required fields are marked

Reviewed by

CCDE/CCIE

How to cite this resource

SMEnode Labs (2026). Docker Compose Commands Cheat Sheet: 12 Commands Explained. SMEnode Labs. https://smenode-labs.com/free-pdf/devops/docker-compose-commands/

APA

SMEnode Labs. (2026). Docker Compose Commands Cheat Sheet: 12 Commands Explained. SMEnode Labs. https://smenode-labs.com/free-pdf/devops/docker-compose-commands/

BibTeX

@misc{smenodelabs2026,
  title = {Docker Compose Commands Cheat Sheet: 12 Commands Explained},
  author = {{SMEnode Labs}},
  year = {2026},
  url = {https://smenode-labs.com/free-pdf/devops/docker-compose-commands/},
  note = {SMEnode Labs}
}