Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

docker cp to a target file on host fails if target file is in a symlinked directory. #31816

Open
florianlaws opened this issue Mar 14, 2017 · 7 comments
Labels
exp/beginner kind/bug Bugs are bugs. The cause may or may not be known at triage time so debugging may be needed. status/claimed version/1.12

Comments

@florianlaws
Copy link

florianlaws commented Mar 14, 2017

Description

docker cp from a file in the container to a target file on the host fails if target filename is in a symlinked directory.

Steps to reproduce the issue:

  1. Start a container
  2. Try to copy a file from the running container to the host.
    On MacOS try e.g. docker cp containerid:/bin/bash /tmp/dockerbash (on MacOS /tmp is a symlink to private/tmp
    On Linux try ln -s /tmp sl docker cp containerid:/bin/bash sl/dockerbash

Describe the results you received:

Error message: not a directory, file was not created.

Describe the results you expected:

File should be copied into /tmp/dockerbash or sl/dockerbask

Output of docker version:

$ docker version
Client:
 Version:      17.03.0-ce
 API version:  1.24 (downgraded from 1.26)
 Go version:   go1.8
 Git commit:   60ccb22
 Built:        
 OS/Arch:      darwin/amd64

Server:
 Version:      1.12.3
 API version:  1.24 (minimum version )
 Go version:   go1.6.3
 Git commit:   6b644ec
 Built:        Wed Oct 26 23:26:11 2016
 OS/Arch:      linux/amd64
 Experimental: false

Output of docker info:

Containers: 47
 Running: 3
 Paused: 0
 Stopped: 44
Images: 147
Server Version: 1.12.3
Storage Driver: aufs
 Root Dir: /mnt/sda1/var/lib/docker/aufs
 Backing Filesystem: extfs
 Dirs: 288
 Dirperm1 Supported: true
Logging Driver: json-file
Cgroup Driver: cgroupfs
Plugins: 
 Volume: local
 Network: host overlay bridge null
Swarm: inactive
Runtimes: runc
Default Runtime: runc
Init Binary: 
containerd version: 
runc version: 
init version: 
Security Options:
 seccomp
Kernel Version: 4.4.27-boot2docker
Operating System: Boot2Docker 1.12.3 (TCL 7.2); HEAD : 7fc7575 - Thu Oct 27 17:23:17 UTC 2016
OSType: linux
Architecture: x86_64
CPUs: 1
Total Memory: 995.8 MiB
Name: default
ID: 52NW:N6TU:3SBB:GXQ2:PHYI:IAW3:5AUC:ZUAA:G6LS:BH4Y:EB52:ACEZ
Docker Root Dir: /mnt/sda1/var/lib/docker
Debug Mode (client): false
Debug Mode (server): true
 File Descriptors: 28
 Goroutines: 43
 System Time: 2017-03-14T10:58:01.490570974Z
 EventsListeners: 0
Registry: https://index.docker.io/v1/
Labels:
 provider=virtualbox
Experimental: false
Insecure Registries:
 127.0.0.0/8
Live Restore Enabled: false```

**Additional environment details (AWS, VirtualBox, physical, etc.):**

Above on MacOs Sierra with docker-machine 0.10.0, but reproducible with Linux too. 
@tonistiigi tonistiigi added kind/bug Bugs are bugs. The cause may or may not be known at triage time so debugging may be needed. exp/beginner labels Mar 15, 2017
@dccurtis
Copy link
Contributor

#dibs

@thaJeztah
Copy link
Member

Thanks @dccurtis let us know if you need help 👍

@dccurtis
Copy link
Contributor

Will do, so far so good!

@dccurtis
Copy link
Contributor

The root cause of this problem is that os.Lstat -> FileInfo.IsDir() returns false for a symlink directory in CopyInfoDestinationPath.

not a directory is thrown whenever you copy a file from a container to a host symlink directory with a new target filename.

I have a fix for this. I'm finishing up my testing and will have a PR out soon!

@karanguptak9
Copy link

#dibs

@dccurtis
Copy link
Contributor

dccurtis commented Apr 6, 2017

@karanguptak9 Just a heads up; my fix was already approved for this. Just waiting on it to be merged.

liusdu pushed a commit to liusdu/moby that referenced this issue Oct 30, 2017
…directory

Description:
‘docker cp’ fails with error ‘not a directory’ if a file is copied from
a container to a host symlinked directory with a new target filename.

The fix is to use os.Stat instead of os.Lstat since os.Stat follows the
linked path.

(Backport from moby#31993)

It is not merged yet.
Link: moby#31816

Signed-off-by: Wentao Zhang <zhangwentao234@huawei.com>
liusdu pushed a commit to liusdu/moby that referenced this issue Oct 30, 2017
Fixing ‘docker cp’ to allow new target file name in a host symlinked directory

Description: 

‘docker cp’ fails with error ‘not a directory’ if a file is copied from
a container to a host symlinked directory with a new target filename.

The fix is to use os.Stat instead of os.Lstat since os.Stat follows the
linked path.

<br>

(Backport from <a href="moby#31993" rel="nofollow noreferrer" target="_blank">https://github.com/moby/moby/pull/31993</a>)

It is not merged yet.

Link:  <a href="moby#31816" rel="nofollow noreferrer" target="_blank">https://github.com/moby/moby/issues/31816</a> 

<br>

Signed-off-by: Wentao Zhang <a href="mailto:zhangwentao234@huawei.com">zhangwentao234@huawei.com</a>



See merge request docker/docker!632
@JBYoshi
Copy link

JBYoshi commented Feb 23, 2023

The PR for this was merged, so I think this can be closed.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
exp/beginner kind/bug Bugs are bugs. The cause may or may not be known at triage time so debugging may be needed. status/claimed version/1.12
Projects
None yet
Development

No branches or pull requests

7 participants