diff --git a/archive.go b/archive.go index b129e28797..16401e29fb 100644 --- a/archive.go +++ b/archive.go @@ -185,9 +185,9 @@ func CopyWithTar(src, dst string) error { } // Create the destination var dstDir string - if dst[len(dst)-1] == '/' { - // The destination ends in / - // --> dst is the holding directory + if srcSt.IsDir() || dst[len(dst)-1] == '/' { + // The destination ends in /, or the source is a directory + // --> dst is the holding directory and needs to be created for -C dstDir = dst } else { // The destination doesn't end in / diff --git a/docs/sources/use/builder.rst b/docs/sources/use/builder.rst index 830d517c0e..5ceba4b210 100644 --- a/docs/sources/use/builder.rst +++ b/docs/sources/use/builder.rst @@ -156,22 +156,15 @@ When a directory is copied or unpacked, it has the same behavior as 'tar -x': th a) whatever existed at the destination path and b) the contents of the source tree, with conflicts resolved in favor of b on a file-by-file basis. -If `` is any other kind of file, it is copied individually along with its metadata. +If `` is any other kind of file, it is copied individually along with its metadata. In this case, +if `` ends with a trailing slash '/', it will be considered a directory and the contents of `` +will be written at `/base()`. +If `` does not end with a trailing slash, it will be considered a regular file and the contents +of `` will be written at ``. If `` doesn't exist, it is created along with all missing directories in its path. All new files and directories are created with mode 0700, uid and gid 0. -If `` ends with a trailing slash '/', the contents of `` is copied `inside` it. -For example "ADD foo /usr/src/" creates /usr/src/foo in the container. If `` already exists, -it MUST be a directory. - -If `` does not end with a trailing slash '/', the contents of `` is copied `over` it. -For example "ADD foo /usr/src" creates /usr/src with the contents of the "foo". If `` already -exists, it MUST be of the same type as the source. - - - - 3. Dockerfile Examples ======================