✦ For everyone, free.

Practical knowledge for real and everyday life

Home

4.2.12.2 VOLUME Persistence Intent

A focused guide to VOLUME Persistence Intent, connecting core concepts with practical Docker and container operations.

VOLUME persistence intent is the signal VOLUME sends, both to Docker and to anyone reading a Dockerfile, that data written to a particular path is meant to outlive the container itself, distinguishing it clearly from the rest of the image's otherwise disposable filesystem.

Communicating Intent Through the Dockerfile

A VOLUME declaration makes the intent behind a particular path explicit and visible directly in the image's own definition, rather than leaving it as an assumption that anyone deploying the image needs to separately understand.

VOLUME /var/lib/postgresql/data

Anyone reading this Dockerfile immediately understands that this path holds data meant to persist, distinct from the rest of the container's filesystem, which is expected to be disposable.

Why This Distinction Matters Operationally

Operators deploying an image benefit from knowing, without needing to inspect application source code, exactly which paths require durable backing storage and which do not — VOLUME declarations make this distinction part of the image's own self-description.

docker inspect myapp:1.0 --format '{{json .Config.Volumes}}'

This reveals declared volume paths directly from the image's metadata, without needing any other documentation.

Persistence Intent Doesn't Guarantee Durability on Its Own

Declaring a path with VOLUME signals intent, but the actual durability of the data depends on what kind of volume is ultimately used — an anonymous volume tied loosely to a container, a named volume managed independently, or a bind mount to a specific, durable host location, each providing different practical guarantees.

docker run -d -v /mnt/durable-storage:/var/lib/postgresql/data postgres:16

Explicitly mounting a known-durable host location fulfills the persistence intent the image declares far more robustly than relying on an anonymous volume alone.

Why Communicating Persistence Intent Matters

Clear persistence intent, expressed directly through VOLUME, helps prevent a common and consequential mistake: running a stateful application without realizing which of its data needs durable storage until that data has already been unexpectedly lost.