From c8db128dc5ec21b7ea6bf6b64dcdebeabf4ee97d Mon Sep 17 00:00:00 2001 From: Michael Juliano Date: Tue, 22 Aug 2017 04:43:11 -0400 Subject: [PATCH] Modified func Upload to use docker cp --- .gitignore | 1 + builder/docker/communicator.go | 21 ++++++++++----------- 2 files changed, 11 insertions(+), 11 deletions(-) diff --git a/.gitignore b/.gitignore index c3dea6687..a23e18aec 100644 --- a/.gitignore +++ b/.gitignore @@ -21,3 +21,4 @@ packer-test*.log .idea/ *.iml +Thumbs.db diff --git a/builder/docker/communicator.go b/builder/docker/communicator.go index b51f40c87..d6b37a1a0 100644 --- a/builder/docker/communicator.go +++ b/builder/docker/communicator.go @@ -79,21 +79,20 @@ func (c *Communicator) Upload(dst string, src io.Reader, fi *os.FileInfo) error } tempfile.Close() - // Copy the file into place by copying the temporary file we put - // into the shared folder into the proper location in the container - cmd := &packer.RemoteCmd{ - Command: fmt.Sprintf("command cp %s/%s %s", c.ContainerDir, - filepath.Base(tempfile.Name()), dst), - } + // Use docker cp to copy the file from the host to the container + // command format: docker cp /path/to/infile containerid:/path/to/outfile + cmd := exec.Command("docker", "cp", tempfile.Name(), fmt.Sprintf("%s:%s", c.ContainerId, dst)) - if err := c.Start(cmd); err != nil { + log.Printf("Copying %s to %s on container %s.", tempfile.Name(), dst, c.ContainerId) + if err := cmd.Start(); err != nil { return err } - // Wait for the copy to complete - cmd.Wait() - if cmd.ExitStatus != 0 { - return fmt.Errorf("Upload failed with non-zero exit status: %d", cmd.ExitStatus) + if err := cmd.Wait(); err != nil { + err = fmt.Errorf("Error uploading %s: %s", + tempfile.Name(), + err) + return err } return nil