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 -L --follow-link fails to dereference file link #21146

Closed
WhisperingChaos opened this issue Mar 12, 2016 · 4 comments
Closed

docker cp -L --follow-link fails to dereference file link #21146

WhisperingChaos opened this issue Mar 12, 2016 · 4 comments
Labels
area/cli kind/bug Bugs are bugs. The cause may or may not be known at triage time so debugging may be needed. version/1.10

Comments

@WhisperingChaos
Copy link
Contributor


BUG REPORT INFORMATION

Output of docker version:

Client:
 Version:      1.10.2
 API version:  1.22
 Go version:   go1.5.3
 Git commit:   c3959b1
 Built:        Mon Feb 22 22:37:33 2016
 OS/Arch:      linux/amd64

Server:
 Version:      1.10.2
 API version:  1.22
 Go version:   go1.5.3
 Git commit:   c3959b1
 Built:        Mon Feb 22 22:37:33 2016
 OS/Arch:      linux/amd64

Output of docker info:

Containers: 0
 Running: 0
 Paused: 0
 Stopped: 0
Images: 5
Server Version: 1.10.2
Storage Driver: vfs
Execution Driver: native-0.2
Logging Driver: json-file
Plugins: 
 Volume: local
 Network: bridge null host
Kernel Version: 3.13.0-74-generic
Operating System: Alpine Linux v3.3 (containerized)
OSType: linux
Architecture: x86_64
CPUs: 4
Total Memory: 7.704 GiB
Name: 97b6482c3a10
ID: XUPJ:VGFT:2B7I:HOQU:BJQ7:3L4S:SGTL:ZAOO:Q57R:WXHL:BFKY:UWQ2
WARNING: No swap limit support
WARNING: bridge-nf-call-iptables is disabled
WARNING: bridge-nf-call-ip6tables is disabled

Additional environment details (AWS, VirtualBox, physical, etc.):
Running docker dind

Steps to reproduce the issue:

  1. Create a directory called test in local host directory.
    >mkdir test
  2. Create a file in test called file whose content is file.
    >echo 'file' >test/file
  3. Create a directory in test called subdir.
    >mkdir test/subdir
  4. Create a link in test/subdir called fileLinked that refers to /test/file.
    >ln -s /test/file /test/subdir/fileLinked
  5. Verify link:
    >ls -al /test/subdir/fileLinked
root@d2c40c688111:/# ls -al /test/subdir/fileLinked
lrwxrwxrwx 1 root root 10 Mar 12 03:02 /test/subdir/fileLinked -> /test/file
  1. Create a container from latest Apline image.

>docker create -it alpine sh
7. Copy test/subdir to container root / and specify -L or --follow-link option.

>docker cp --follow-link /test/subdir 858a81c497b7:/
8. Start and attach to the container.

>docker start -i 858a81c497b7
9. From container command line verify link was dereferenced.

/ # ls -al /subdir/fileLinked
lrwxrwxrwx    1 root     root            10 Mar 12 03:02 /subdir/fileLinked -> /test/file
/ # cat /subdir/fileLinked
cat: can't open '/subdir/fileLinked': No such file or directory

Describe the results you received:
/subdir/fileLinked remained a symbolic link when copied into a container.

Describe the results you expected:
As described in cp documentation If you specify the -L option, docker cp follows any symbolic link in the SRC_PATH. Also see #16613. Follow link option typically replaces the symbolic link with a copy of the actual file.

Additional information you deem important (e.g. issue happens only occasionally):
Also occurs when container is SRC_PATH and SRC_PATH directory contains a symbolically linked file.

@WeiZhang555
Copy link
Contributor

This is by design, when you run docker cp --follow-link /test/subdir 858a81c497b7:/, it won't resolve symbol link in /test/subdir, this command means "if /test/subdir is a symbol link, copy the target directory /test/subdir points to".

See #16613 (comment)

@programmerq programmerq added area/cli kind/bug Bugs are bugs. The cause may or may not be known at triage time so debugging may be needed. labels Mar 31, 2016
@simskij
Copy link

simskij commented May 31, 2019

This is by design, when you run docker cp --follow-link /test/subdir 858a81c497b7:/, it won't resolve symbol link in /test/subdir, this command means "if /test/subdir is a symbol link, copy the target directory /test/subdir points to".

See #16613 (comment)

So, to summarize:

docker cp --follow-link /test/subdir 858a81c497b7:/ will copy the folder subdir to the specified target, following links if the subdir happens to be a symlink. however, it will not follow links for any of its children.

to achieve what @WhisperingChaos were after, one would instead have to:

$ docker exec -it 858a81c497b7 mkdir /subdir
$ docker cp --follow-link /test/subdir/* 858a81c497b7:/subdir/

And btw, this issue should likely be closed.
Maybe someone on the @moby team can take care of that? 🙏

@simskij
Copy link

simskij commented Jun 11, 2019

Ping @thaJeztah.

@thaJeztah
Copy link
Member

👍 thanks for digging up the history and adding the explanation; I'll close

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

No branches or pull requests

6 participants