In my container, I have a folder that contains a relative symlink to a parent's parent subfolder:
$ docker run --name symlink-test ubuntu bash -c "mkdir -p /1/2; touch /1/2/a; ln -s ../../usr /1/2; touch /1/2/z; ls -l /1/2" :(
total 4
-rw-r--r--. 1 root root 0 Mar 4 03:37 a
lrwxrwxrwx. 1 root root 9 Mar 4 03:37 usr -> ../../usr
-rw-r--r--. 1 root root 0 Mar 4 03:37 z
I want to copy the folder /1
to the host. However, I always get the following error:
$ docker cp symlink-test:/1/2
invalid symlink "/tmp/2/usr" -> "../../usr"
$ ls 2
a
Copying the files fails and docker cp
aborts after it sees the symlink.
There are some Docker bugs related to this, but they are either fixed or were caused by something different:
I'm running Docker 1.10.2 on Fedora 23.
Is the above behavior of docker cp
intended or is it a bug? If it is intended, what's the reasoning behind it?
In my case, I get it to work by:
docker cp -L container:/path/to/file.png current/directory/file.png
I don't know whether this behavior is intentional, but here's a workaround:
docker cp my-container:/path/to/dir - | tar -x
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With