✦ For everyone, free.

Practical knowledge for real and everyday life

Home

8.2.2.2 Anonymous Hidden Persistence

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

Anonymous hidden persistence describes the situation where an anonymous volume actually does hold important data — created automatically due to an image's VOLUME declaration — but without a meaningful name, making this persistence easy to overlook entirely until it surprises someone managing the system.

How Important Data Can End Up in an Easily Overlooked Volume

A container run without explicit volume configuration can still end up persisting important data automatically, due to the image's own VOLUME declaration silently creating an anonymous volume behind the scenes.

docker run -d --name database postgres:16
docker volume ls

This reveals an anonymous volume automatically created for the database's data directory, holding genuinely important data despite the user never having explicitly requested any volume configuration at all.

Why This Hidden Persistence Can Cause Confusion

Removing and recreating this container without realizing an anonymous volume is already holding its data can lead to either unexpectedly losing access to that data (if the anonymous volume is also removed) or unexpectedly retaining stale data (if a new anonymous volume is created instead, while the old one lingers, forgotten).

docker rm -v database
docker run -d --name database postgres:16

The -v flag on removal here deletes the previous anonymous volume; without it, that volume would persist, unreferenced and easily forgotten, while the new container creates yet another fresh anonymous volume.

Surfacing This Hidden Persistence Explicitly

Checking exactly what volumes a running container is actually using reveals this hidden persistence before it becomes a source of confusion.

docker inspect database --format '{{json .Mounts}}'
The Fix: Making Persistence Explicit With a Named Volume

Replacing this implicit, anonymous persistence with an explicit, named volume removes the ambiguity entirely.

docker run -d --name database -v pgdata:/var/lib/postgresql/data postgres:16
Why Anonymous Hidden Persistence Matters

Recognizing that an image's own VOLUME declaration can silently create meaningful, persistent storage without any explicit request is important for avoiding the confusion and potential data mismanagement that comes from not realizing important data is being held in an easily overlooked anonymous volume.