docker / for-win

Bug reports for Docker Desktop for Windows
https://www.docker.com/products/docker#/windows
1.85k stars 287 forks source link

Symlinks broken behavior #8656

Open iSeiryu opened 3 years ago

iSeiryu commented 3 years ago

Expected behavior

The build can see the target file that symlink points to

Actual behavior

It works as expected inside WSL but not on Windows itself. I (and other devs) get "No such file or directory" when running on Win 10.

Information

Steps to reproduce the behavior

  1. Just need anything with a symlink to a file in it. My test folder structure
    symlink-test
    +-- common
    |   +-- target-file.txt  --  contains "Hello from the target-file!"
    +-- Dockerfile
    +-- link.txt -> common/target-file.txt

to create a soft link use mklink on Win or ln on Linux

ln -s common/target-file.txt link.txt
  1. My test Dockerfile (I used all sorts of images, not just vault):
    FROM vault
    WORKDIR /src
    COPY . .
    RUN ls -al && cat link.txt
  2. When I run it inside WSL2 (my Docker Desktop runs on it too) it works just fine
    /mnt/c/work/repos/test/symlink-test$ docker build . -t symlink-test:latest
    Sending build context to Docker daemon  4.096kB
    Step 1/4 : FROM vault
    ---> aac433bb6835
    Step 2/4 : WORKDIR /src
    ---> Using cache
    ---> 3b1f2703087a
    Step 3/4 : COPY . .
    ---> c858c20b96aa
    Step 4/4 : RUN ls -al && cat link.txt
    ---> Running in f9a8325ca6b0
    total 16
    drwxr-xr-x    1 root     root          4096 Sep 24 20:44 .
    drwxr-xr-x    1 root     root          4096 Sep 24 20:44 ..
    -rwxrwxrwx    1 root     root            62 Sep 24 20:39 Dockerfile
    drwxrwxrwx    2 root     root          4096 Sep 24 20:33 common
    lrwxrwxrwx    1 root     root            22 Sep 24 20:37 link.txt -> common/target-file.txt
    Hello from the target-file!
    Removing intermediate container f9a8325ca6b0
    ---> d85501725e83
    Successfully built d85501725e83
    Successfully tagged symlink-test:latest

But when I run it on Win 10 it gives me this:

docker build . -t symlink-test:latest
Sending build context to Docker daemon  4.096kB
Step 1/4 : FROM vault
 ---> aac433bb6835
Step 2/4 : WORKDIR /src
 ---> Using cache
 ---> 3b1f2703087a
Step 3/4 : COPY . .
 ---> Using cache
 ---> 9b909a2f9af8
Step 4/4 : RUN ls -al && cat link.txt
 ---> Running in 37cb902aa2a4
total 16
drwxr-xr-x    1 root     root          4096 Sep 24 20:43 .
drwxr-xr-x    1 root     root          4096 Sep 24 21:10 ..
-rwxr-xr-x    1 root     root            62 Sep 24 20:39 Dockerfile
drwxr-xr-x    2 root     root          4096 Sep 24 20:33 common
lrwxrwxrwx    1 root     root            22 Sep 24 20:37 link.txt -> common\target-file.txt
cat: can't open 'link.txt': No such file or directory
The command '/bin/sh -c ls -al && cat link.txt' returned a non-zero code: 1
iSeiryu commented 3 years ago

I've read through the SO questions like these 2 https://stackoverflow.com/questions/31881904/docker-follow-symlink-outside-context https://stackoverflow.com/questions/42569303/docker-does-not-follow-symlinks-within-build-directory

If this is not supported at all why is it working inside our CICD and inside our WSL 2? We can reproduce it on different machines.

docker-robott commented 3 years ago

Issues go stale after 90 days of inactivity. Mark the issue as fresh with /remove-lifecycle stale comment. Stale issues will be closed after an additional 30 days of inactivity.

Prevent issues from auto-closing with an /lifecycle frozen comment.

If this issue is safe to close now please do so.

Send feedback to Docker Community Slack channels #docker-for-mac or #docker-for-windows. /lifecycle stale

iSeiryu commented 3 years ago

/remove-lifecycle stale

docker-robott commented 3 years ago

Issues go stale after 90 days of inactivity. Mark the issue as fresh with /remove-lifecycle stale comment. Stale issues will be closed after an additional 30 days of inactivity.

Prevent issues from auto-closing with an /lifecycle frozen comment.

If this issue is safe to close now please do so.

Send feedback to Docker Community Slack channels #docker-for-mac or #docker-for-windows. /lifecycle stale

iSeiryu commented 3 years ago

/lifecycle frozen