docker cp -L --follow-link fails to dereference file link
Closed this issue · 4 comments
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:
- Create a directory called
test
in local host directory.
>mkdir test
- Create a file in
test
calledfile
whose content isfile
.
>echo 'file' >test/file
- Create a directory in
test
calledsubdir
.
>mkdir test/subdir
- Create a link in
test/subdir
calledfileLinked
that refers to/test/file
.
>ln -s /test/file /test/subdir/fileLinked
- 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
- 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.
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)
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? 🙏
Ping @thaJeztah.
👍 thanks for digging up the history and adding the explanation; I'll close