Compose state and cleanup
Treat a Compose project as a small system with services, networks, volumes, and lifecycle.
docker compose logs
20 min read, 30 min lab
operator
Compose coordinates multiple containers. `ps`, `logs`, `config`, and `down` tell you what exists and how it was defined. Cleanup should be explicit about containers, networks, and volumes.
A local stack works once, then fails after a restart because stale volume state remains.
Worked command
$ docker compose ps$ docker compose logs --tail 100 api$ docker compose config$ docker compose down$ docker compose down --volumes
Do not delete volumes casually; they may contain the data you need to inspect.
Name what cleanup removes before running it.
A stack works once but breaks after a restart due to stale state. You run `docker compose down --volumes`. What extra risk does the --volumes flag add over plain down?
Show the answer
Correct: B. It deletes named and anonymous volumes, destroying persisted data
down --volumes removes the project's named and anonymous volumes, so any data you needed to inspect for the stale-state bug is gone. The trap is assuming named data is safe; plain down stops containers and removes the network but keeps volumes, which is why it is the reversible default.
Practice checklist
- Inspect a disposable Compose project or sample output.
- Collect ps/logs/config evidence.
- Write a cleanup command and what it removes.
Deliverable evidence
- Compose inspection packet and cleanup note.
shows: The outside-in debugging order — ps, logs, ports/mounts, then exec only on a hypothesis — plus the Compose lifecycle from down (keeps named volumes) to down --volumes (destroys them).
does not prove: The order tells you where to look, not what is wrong; a clean log and a present port mapping narrow the cause but do not by themselves prove the service is healthy.
Commit these to memory, then drill them until recall is automatic.
cue Compose: tear down the stack but keep volume data intact
show recall target
docker compose down