Moving a database volume from one Docker host to another.
IntermediateScenarioVolumes, storage and data
Answer
Situation read → Need consistent data transfer with minimal downtime.
What I'd do →
- Prefer a logical migration:
pg_dump | psqlor replication. - If you must copy files, stop the container first, then:
docker run --rm -v pgdata:/from alpine tar c -C /from . | \
ssh new-host 'docker run --rm -i -v pgdata:/to alpine tar x -C /to'
- Start with the same image major version.
Why → Copying files from a running DB risks corruption.
Interview tip → Same major version is mandatory for binary data directories.
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?BeginnerHow do you back up a named volume?IntermediateTwo containers must share files. What are your options?BeginnerA container needs a writable temp area but the root filesystem is read-only.IntermediateExplain how copy-on-write affects performance of a write-heavy container.Advanced