Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Best way to copy files from Docker volume on remote server to local host?

I've got,

  1. My laptop
  2. A remote server I can SSH into which has a Docker volume inside of which are some files I'd like to copy to my laptop.

What is the best way to copy these files over? Bonus points for using things like rsync, etc.. which are fast / can resume / show me progress and not writing any temporary files.

Note: my user on the remote server does not have permission to just scp the data straight out of the volume mount in /var/lib/docker, although I can run any containers on there.

like image 720
marius Avatar asked Dec 18 '15 15:12

marius


People also ask

How do I copy a file from docker container to local host?

Issue the docker cp command and reference the container name or id. The first parameter of the docker copy command is the path to the file inside the container. The second parameter of the docker copy command is the location to save the file on the host.

How do I copy multiple files from docker container to local machine?

Another way to copy files to and from Docker containers is to use a volume mount. This means we make a directory from the host system available inside the container. The command above runs a grafana container and mounts the /tmp directory from the host machine as a new directory inside the container named /transfer.

Can I copy docker volume to another host?

Transfer a volume to another Docker hostFrom the extension, you can specify both the destination host the local volume copied to (for example, [email protected] ) and the destination volume. > SSH must be enabled and configured between the source and destination Docker hosts.


2 Answers

Having this problem, I created dvsync which uses ngrok to establish a tunnel that is being used by rsync to copy data even if the machine is in a private VPC. To use it, you first start the dvsync-server locally, pointing it at the source directory:

$ docker run --rm -e NGROK_AUTHTOKEN="$NGROK_AUTHTOKEN" \
  --mount source=MY_DIRECTORY,target=/data,readonly \
  quay.io/suda/dvsync-server

Note, you need the NGROK_AUTHTOKEN which can be obtained from ngrok dashboard. Then start the dvsync-client on the target machine:

docker run -e DVSYNC_TOKEN="$DVSYNC_TOKEN" \
  --mount source=MY_TARGET_VOLUME,target=/data \
  quay.io/suda/dvsync-client

The DVSYNC_TOKEN can be found in dvsync-server output and it's a base64 encoded private key and tunnel info. Once the data has been copied, the client wil exit.

like image 140
suda Avatar answered Sep 28 '22 22:09

suda


I'm not sure about the best way of doing so, but if I were you I would run a container sharing the same volume (in read-only -- as it seems you just want to download the files within the volume) and download theses.

This container could be running rsync as you wish.

like image 43
Auzias Avatar answered Sep 29 '22 00:09

Auzias