What is the difference between docker compose stop, down and down -v?
stop halts containers but keeps them. down stops and removes containers and networks. down -v also deletes the named volumes, which destroys stored data.
Explain it simply
Three levels of closing a shop. stop pulls down the shutters; everything is inside, ready to reopen. down clears the shop and removes the signboard but leaves the storeroom. down -v also empties the storeroom.
docker compose stop halts services; start brings the same containers back. docker compose down removes the containers and the project's networks, so the next up creates fresh containers. Named volumes remain, so a database keeps its data. Adding -v deletes volumes declared in the compose file too, and --rmi all additionally removes images.
A developer who wants a clean database for tests uses down -v. A developer who wants to keep data uses plain down or stop.
Example
docker compose stop # containers kept, stopped
docker compose start # same containers resume
docker compose down # containers + networks removed, volumes kept
docker compose down -v # also deletes volumes (data loss)What to say in the interview
"stop only halts containers. down removes containers and networks but keeps volumes. down -v also removes the volumes, so I use it only when I want a clean slate."
Common mistakes
- Running down -v on a stack whose volume holds real data.