Files
docker-docs/machine/reference/scp.md
Misty Stanley-Jones a4f5e30249 Various copyedits to reduce future tense, wordiness, and use of 'please' (#5788)
* Reword lots of instances of 'will'

* Reword lots of instances of won't

* Reword lots of instances of we'll

* Eradicate you'll

* Eradicate 'be able to' type of phrases

* Eradicate 'unable to' type of phrases

* Eradicate 'has / have to' type of phrases

* Eradicate 'note that' type of phrases

* Eradicate 'in order to' type of phrases

* Redirect to official Chef and Puppet docs

* Eradicate gratuitous 'please'

* Reduce use of e.g.

* Reduce use of i.e.

* Reduce use of N.B.

* Get rid of 'sexagesimal' and correct some errors
2018-01-25 17:37:23 -08:00

2.5 KiB

description, keywords, title
description keywords title
Copy files among machines machine, scp, subcommand docker-machine scp

Copy files from your local host to a machine, from machine to machine, or from a machine to your local host using scp.

The notation is machinename:/path/to/files for the arguments; in the host machine's case, you don't need to specify the name, just the path.

Example

Consider the following example:

$ cat foo.txt
cat: foo.txt: No such file or directory
$ docker-machine ssh dev pwd
/home/docker
$ docker-machine ssh dev 'echo A file created remotely! >foo.txt'
$ docker-machine scp dev:/home/docker/foo.txt .
foo.txt                                                           100%   28     0.0KB/s   00:00
$ cat foo.txt
A file created remotely!

Just like how scp has a -r flag for copying files recursively, docker-machine has a -r flag for this feature.

In the case of transferring files from machine to machine, they go through the local host's filesystem first (using scp's -3 flag).

When transferring large files or updating directories with lots of files, you can use the -d flag, which uses rsync to transfer deltas instead of transferring all of the files.

When transferring directories and not just files, avoid rsync surprises by using trailing slashes on both the source and destination. For example:

$ mkdir -p bar
$ touch bar/baz
$ docker-machine scp -r -d bar/ dev:/home/docker/bar/
$ docker-machine ssh dev ls bar
baz

Specifying file paths for remote deployments

When you copy files to a remote server with docker-machine scp for app deployment, make sure docker-compose and the Docker daemon know how to find them. Avoid using relative paths, but specify absolute paths in Compose files. It's best to specify absolute paths both for the location on the Docker daemon and within the container.

For example, imagine you want to transfer your local directory /Users/londoncalling/webapp to a remote machine and bind mount it into a container on the remote host. If the remote user is ubuntu, use a command like this:

$ docker-machine scp -r /Users/londoncalling/webapp MACHINE-NAME:/home/ubuntu/webapp

Then write a docker-compose file that bind mounts it in:

version: "3.1"
services:
  webapp:
    image: alpine
    command: cat /app/root.php
    volumes:
    - "/home/ubuntu/webapp:/app"

And we can try it out like so:

$ eval $(docker-machine env MACHINE-NAME)
$ docker-compose run webapp