Interview Prep/Docker/Volumes, storage and data

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 →

  1. Prefer a logical migration: pg_dump | psql or replication.
  2. 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'
  1. 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.

All Docker questions Roadmap: Docker & containers

More on Volumes, storage and data