From f051c2852e30322cb071d9301f29d44f817dda5d Mon Sep 17 00:00:00 2001 From: Ian Rodney Date: Mon, 24 Aug 2020 09:18:34 -0700 Subject: [PATCH] [docker] `docker cp` correctly into container (#10253) --- python/ray/autoscaler/command_runner.py | 8 ++++++++ 1 file changed, 8 insertions(+) diff --git a/python/ray/autoscaler/command_runner.py b/python/ray/autoscaler/command_runner.py index 1d1602708..1da2f8836 100644 --- a/python/ray/autoscaler/command_runner.py +++ b/python/ray/autoscaler/command_runner.py @@ -617,6 +617,10 @@ class DockerCommandRunner(SSHCommandRunner): f"mkdir -p {os.path.dirname(target.rstrip('/'))}") self.ssh_command_runner.run_rsync_up(source, target) if self._check_container_status(): + if os.path.isdir(source): + # Adding a "." means that docker copies the *contents* + # Without it, docker copies the source *into* the target + target += "/." self.ssh_command_runner.run("docker cp {} {}:{}".format( target, self.docker_name, self._docker_expand_user(protected_path))) @@ -627,6 +631,10 @@ class DockerCommandRunner(SSHCommandRunner): source = source.replace("/root", "/tmp/root") self.ssh_command_runner.run( f"mkdir -p {os.path.dirname(source.rstrip('/'))}") + if protected_path[-1] == "/": + protected_path += "." + # Adding a "." means that docker copies the *contents* + # Without it, docker copies the source *into* the target self.ssh_command_runner.run("docker cp {}:{} {}".format( self.docker_name, self._docker_expand_user(protected_path), source))