✦ For everyone, free.

Practical knowledge for real and everyday life

Home

8.2.1 Named Volumes

A focused guide to Named Volumes, connecting core concepts with practical Docker and container operations.

Named volumes are volumes explicitly created with a specific, meaningful name, making them easy to identify, reference consistently across multiple container runs, and manage deliberately, in contrast to anonymous volumes whose randomly generated names make them harder to track.

Creating and Referencing a Named Volume

A named volume is created with an explicit name, then referenced by that same name whenever a container needs to use it.

docker volume create app-database-data
docker run -d --name db -v app-database-data:/var/lib/postgresql/data postgres:16
Why a Meaningful Name Provides Real Value

A descriptive name immediately communicates the volume's purpose, making it far easier to manage correctly compared to an anonymous volume's randomly generated, meaningless identifier.

docker volume ls
app-database-data
a3f7e9c12b4d8f1e6a9b2c5d8e1f4a7b

The named volume's purpose is immediately clear from its name; the anonymous volume's purpose would require additional investigation to determine.

Reattaching the Same Named Volume Across Container Recreations

Because the name is explicit and consistent, recreating a container while correctly referencing the same named volume reliably reattaches the exact same underlying data.

docker rm -f db
docker run -d --name db -v app-database-data:/var/lib/postgresql/data postgres:16

This new container correctly reattaches to the exact same data the previous one was using, since both explicitly reference the same named volume.

Backing Up a Named Volume by Its Known Name

A named volume's explicit, known name makes it straightforward to target specifically for backup or inspection purposes.

docker run --rm -v app-database-data:/data -v $(pwd):/backup alpine tar czf /backup/db-backup.tar.gz /data
Why Named Volumes Matter

Explicitly naming volumes, rather than relying on anonymous ones, is a small but valuable practice that makes data genuinely manageable — easy to identify, reliably reattach, and deliberately back up — rather than risking the confusion and potential data loss anonymous volumes can introduce over time.

Content in this section