I have a large file on my laptop (localhost). I would like to copy this file to a docker container which is located on a remote server. I know how to do it in two steps, i.e. I first copy the file to my remote server and then I copy the file from remote server to the docker container. But, for obvious reasons, I want to avoid this.
A similar question which has a complicated answer is covered here: Copy file from remote docker container
However in this question, the direction is reversed, the file is copied from the remote container to localhost.
Additional request: is it possible that this upload can be done piece-wise or that in case of a network failure I can resume the upload from where it stopped, instead of having to upload the entire file again? I ask because the file is fairly large, ~13GB.
3
Answers
From https://docs.docker.com/engine/reference/commandline/cp/#corner-cases and https://www.cyberciti.biz/faq/howto-use-tar-command-through-network-over-ssh-session/ you would just do:
or
Or untested, no idea if this works:
This will work if you are running a *nix server and a docker with ssh server in it.
You can create a local tunnel on the remote server by following these steps:
First command will create a pipe that you can check with
file host_to_docker
.Second one is the greatest network utility of all times that is
netcat
. It just accepts a tcp connection and forwards it to another netcat instance, receiving and forwarding underlying ssh messages to the ssh server running on docker and writing its responses to the pipe we created.last step is:
You can use the
DOCKER_HOST
environment variable andrsync
to archive your goal.First, you set
DOCKER_HOST
, which causes your docker client (i.e., thedocker
CLI util) to be connected to the remote server’s docker daemon over SSH. This probably requires you to create an ssh-config entry for the destination server.Next, you can use
docker exec
in conjunction withrsync
to copy your data into the target container. This requires you to obtain the container ID via, e.g.,docker ps
. Note, thatrsync
must be installed in the container.Since
rsync
is used, this will also allow you to resume (if the appropriated flags are used) uploads at some point later.