Docker Course
Docker
/
Intermediate

Compose Volumes

Definition

The declarative method for defining persistent Docker volumes at the bottom of a `docker-compose.yml` file, allowing multiple services to mount and share the same data.

Explain Like I'm New

Telling the conductor to prepare the external hard drives before starting the orchestra.

Real World Example

You define a top-level `volumes: { db_data: {} }` block in the YAML. Then, inside the database service, you map `db_data:/var/lib/mysql`. When you run `docker-compose down`, the containers are destroyed, but Compose intelligently preserves the `db_data` volume on the hard drive.

Common Use Cases

  • •Data persistence
  • •Multi-service data sharing

Interview Questions

basic

  • If you run `docker-compose down`, does it automatically delete the Compose Volumes you created?

intermediate

  • How do you completely destroy the entire app, INCLUDING the persistent database volumes?

Flash Cards

Question

Does it delete volumes?

Click to reveal answer
Answer

No. By default, `docker-compose down` deletes containers and networks, but explicitly leaves Volumes intact to prevent accidental data loss.

Question

Destroy everything?

Click to reveal answer
Answer

You must append the volume flag: `docker-compose down --volumes` (or `-v`). This completely wipes the containers, networks, AND the persistent databases.