How do you back up a named volume?
IntermediateScenarioVolumes, storage and data
Answer
Situation read → Volume data lives under /var/lib/docker/volumes, but you should not poke at it directly.
What I'd do →
docker run --rm -v pgdata:/data:ro -v $PWD:/backup alpine \
tar czf /backup/pgdata-$(date +%F).tgz -C /data .
For databases prefer logical dumps or snapshot after CHECKPOINT/with the DB quiesced, because a file copy of a running DB can be inconsistent.
Why → A helper container uses the Docker API and respects drivers.
Interview tip → Test restores, not just backups.
More on Volumes, storage and data
A Postgres container was removed and the data is gone. How should it have been run?BeginnerBind mount or named volume for local development of a Node app?BeginnerTwo containers must share files. What are your options?BeginnerA container needs a writable temp area but the root filesystem is read-only.IntermediateMoving a database volume from one Docker host to another.IntermediateExplain how copy-on-write affects performance of a write-heavy container.Advanced