Filters
How to search
  • Plain words find names, texts and examples.
  • "two words" finds the exact phrase.
  • --name or -x finds an option.
  • #word looks only inside commands.
  • @grep finds lessons and labs that use grep.
  • Filters: cat:network · in:labs · in:notes · level:rhcsa · ch:8 · root:yes. Put ! before a word to leave it out. OR between words means one of them.
  • ↑ ↓ to move · Enter to open · Esc to close · / to search

Docker & containersIT series

9 docker compose commands for daily work

Docker Compose runs a whole multi-container app from a single file. Nine commands cover almost all daily work, from starting the stack to looking inside it. Modern Docker uses docker compose, two words; older setups use docker-compose.

Quick reference

Run it — Start, stop, rebuild

# Start the whole stack in the background.
docker compose up -d
# Stop and remove it. Add -v to delete volumes too.
docker compose down
# Rebuild images, then start. After code changes.
docker compose up -d --build

Look inside — What is going on?

# Which services are up, and their status and ports.
docker compose ps
# Follow one service's logs live.
docker compose logs -f api
# A shell inside a running service.
docker compose exec api sh

Manage — Scale, config, clean

# Run three copies of one service.
docker compose up -d --scale worker=3
# Show the final, merged configuration.
docker compose config
# Fetch newer images before the next up.
docker compose pull

Explained

Run it

docker compose up -d starts every service defined in the file, in the background. App, database, cache and more come up wired together. docker compose down stops and removes the containers and network. Add -v to also delete the named volumes, which wipes the data, so use it deliberately. docker compose up -d --build rebuilds the images first. This is the one people forget after changing code, then wonder why nothing changed.

Look inside

docker compose ps shows which services are running, their status, and the ports they expose. docker compose logs -f api follows one service's logs live. Leave off the name to tail everything at once. docker compose exec api sh opens a shell inside a running service, to check files, config or connectivity.

Manage

docker compose up -d --scale worker=3 runs three copies of a service, handy for testing a queue worker. docker compose config prints the final configuration after merging files and variables. It catches YAML and variable mistakes before they bite. docker compose pull fetches newer versions of the images before your next up.

The daily rhythm is simple: up -d to start, logs -f to watch, down to stop.

In one line

One file, the whole stack. Compose is the fastest way to run a real app locally.

The daily two

docker compose up -d && docker compose logs -f

More notes: Docker & containers

Open in the notes app: search, filters, copy This note on GitHub