CodePark/ questions / Volumes & bind mounts
START PRACTICINGPRACTICE
Backend question · Docker › Volumes & bind mounts

Your compose.yaml declares a named volume pgdata for Postgres. Which command removes the containers and also deletes the database data?

docker compose down -v

docker compose down -v is right. -v is short for --volumes. It removes the containers and networks, and also deletes:
• the named volumes declared in the file, such as
pgdata
• anonymous volumes attached to the containers


Plain
docker compose down removes containers and networks but keeps named volumes, so your data survives. docker compose stop only stops the containers. docker compose rm -f removes stopped containers but does not delete named volumes.