A stack is taken down with one command. Here: what stays after it.
A service connects a named volume by name, and the volume itself is declared at the top level of the file — with the volumes: key next to services:. compose prefixes the volume name with the project name: the volume pgdata of the project shop is called shop_pgdata.
docker compose down stops and removes the project's containers and its network. The volumes stay: the data outlives re-creating the stack. To remove them along with the stack — docker compose down -v.
~/notes/compose.yaml declares the volume notes-data. The stack was taken down with sudo docker compose down. What will sudo docker volume ls show?
-
compose prefixes the volume name with the project name, the
notesdirectory: the volume is callednotes_notes-data. -
notes_defaultis the project's network, anddownremoves it.sudo docker network lslists networks,sudo docker volume lslists volumes. -
downremoves the project's containers and network but keeps the volumes.docker compose down -vremoves the stack together with its volumes.
down removes the project's containers and network and keeps its volumes, so the data outlives re-creating the stack. compose built the volume name from the project name and the name in the file: notes_notes-data.
Key points
-
A named volume is declared with the top-level
volumes:key and is called<project>_<volume>. -
downremoves the project's containers and network; the volumes stay. -
down -vremoves the volumes along with the stack.