Interview Prep/Docker/Volumes, storage and data

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.

All Docker questions Roadmap: Docker & containers

More on Volumes, storage and data