पाठ 3 / 25
The Compose Lifecycle
up, ps, logs, exec, down.
Everyday commands
docker compose up -d builds images if needed, creates networks and volumes, and starts services in the background; ps lists them; logs -f follows combined logs; exec <service> sh opens a shell inside a running container; run --rm <service> <cmd> runs one-off tasks such as migrations; down stops and removes containers and networks (add -v to also delete named volumes, which deletes data). config prints the fully resolved configuration and validates it, without starting anything.
A typical session (sketch)
Commands that start containers need a running Docker engine; not run here.
docker compose up -d --build # build images and start in the background
docker compose ps # status and health of each service
docker compose logs -f api # follow one service's logs
docker compose exec db psql -U shop # shell into a running container
docker compose run --rm api npm run migrate # one-off task
docker compose down # stop and remove containers + networks (volumes kept)Be careful with down -v
down -v deletes named volumes, including database data; use it only when you mean to reset.
त्वरित जाँच: Which command removes containers AND deletes named volumes?
- docker compose config
- docker compose stop
- docker compose ps
- docker compose down -v
Answer
docker compose down -v — Volumes survive a plain down.