How to copy docker volume from one machine to another?

I have created a docker volume for postgres on my local machine.

docker create volume postgres-data

Then I used this volume and run a docker.

  • Docker file to run Python with Pandas
  • Can't get remote Hazelcast client to connect to cluster running in docker containers
  • docker pentaho mysql driver issue
  • Can't npm install dependencies when building docker image
  • Install SCP in Docker container
  • Docker, how to expose a socket over a port for a Django Application
  • docker run -it -v postgres-data:/var/lib/postgresql/9.6/main postgres
    

    After that I did some database operations which got stored automatically in postgres-data. Now I want to copy that volume from my local machine to another remote machine. How to do the same.

    Note – Database size is very large

  • OSX terminal vs Docker CLI
  • How does Docker allow portable containers if the Kernel libraries change
  • Docker container cannot access internet
  • Public IP mapping to internal shared virtual ip address in Docker
  • Use environment variables in docker
  • Dockerfile and docker-compose not updating with new instructions
  • One Solution collect form web for “How to copy docker volume from one machine to another?”

    If the second machine has SSH enabled you can use an Alpine container on the first machine to map the volume, bundle it up and send it to the second machine.

    That would look like this:

    docker run --rm -v <SOURCE_DATA_VOLUME_NAME>:/from alpine ash -c "cd /from ; tar -cf - . " | ssh <TARGET_HOST> 'docker run --rm -i -v <TARGET_DATA_VOLUME_NAME>:/to alpine ash -c "cd /to ; tar -xpvf - " 
    

    You will need to change:

    • SOURCE_DATA_VOLUME_NAME
    • TARGET_HOST
    • TARGET_DATA_VOLUME_NAME

    Or, you could try using this helper script https://github.com/gdiepen/docker-convenience-scripts

    Hope this helps.

    Docker will be the best open platform for developers and sysadmins to build, ship, and run distributed applications.