Quiz Entry - updated: 2026.12.01
Which Docker Compose commands manage a stack's lifecycle, and when do you use build: instead of image:?
docker compose up -d creates and starts everything, logs/top observe it, down stops and removes it; build: <folder> builds the service from a Dockerfile, together with up --build.
| Command | Effect |
|---|---|
docker compose up -d |
Creates the networks and volumes, pulls or builds images, starts all services in the background |
docker compose up --build -d |
Same, but rebuilds images from their Dockerfiles first |
docker compose ps |
Lists the stack's containers |
docker compose logs --tail=10 |
Last 10 log lines of every service (useful with -d, where logs aren't on screen) |
docker compose top |
The processes running inside each service's containers |
docker compose down |
Stops and removes containers and networks; named volumes stay unless you add -v |
image: vs build:
image: mysql:5.7uses a ready-made image from a registry (or one already built locally).build: backendtells Compose to build the image from the Dockerfile in thebackend/folder. That is how your own services enter the stack. Without--build, Compose reuses an image it built earlier, so code changes would not show up.
Compose names its resources after the project (the folder name by default), for example dockercompose_db_data and dockercompose_default, so several stacks on one host don't collide.
Go deeper:
Docker Docs: docker compose up —
--build,-dand the other options.Docker Docs: docker compose down — what is removed, and
-vfor volumes.Docker Docs: Version and name top-level elements — why
version:is obsolete and how the project name is set.