docker / buildx

Docker CLI plugin for extended build capabilities with BuildKit
Apache License 2.0
3.55k stars 481 forks source link

Symlinks are not handled correctly when BUILDKIT is enabled #611

Open mortada opened 3 years ago

mortada commented 3 years ago

Here's a minimal example to reproduce this problem

mkdir -p other_dir/sub_dir/{a,b}
ln -s other_dir/sub_dir
echo a > sub_dir/a/file
echo b > sub_dir/b/file

The directory structure is:

$ tree
.
├── Dockerfile
├── other_dir
│   └── sub_dir
│       ├── a
│       │   └── file
│       └── b
│           └── file
└── sub_dir -> other_dir/sub_dir

Dockerfile:

FROM alpine

COPY sub_dir/a /opt/a
COPY sub_dir/b /opt/b

RUN cat /opt/a/file
RUN cat /opt/b/file

DOCKER_BUILDKIT=0 docker build . -t dummy builds successfully, while DOCKER_BUILDKIT=1 produces the following error:

$ DOCKER_BUILDKIT=1 docker build . -t dummy
[+] Building 0.1s (7/9)
 => [internal] load build definition from Dockerfile                                                                        0.0s
 => => transferring dockerfile: 43B                                                                                         0.0s
 => [internal] load .dockerignore                                                                                           0.0s
 => => transferring context: 2B                                                                                             0.0s
 => [internal] load metadata for docker.io/library/alpine:latest                                                            0.0s
 => [1/5] FROM docker.io/library/alpine                                                                                     0.0s
 => [internal] load build context                                                                                           0.0s
 => => transferring context: 197B                                                                                           0.0s
 => CACHED [2/5] COPY sub_dir/a /opt/a                                                                                      0.0s
 => ERROR [3/5] COPY sub_dir/b /opt/b                                                                                       0.0s
------
 > [3/5] COPY sub_dir/b /opt/b:
------
failed to compute cache key: "/sub_dir/b" not found: not found

I run this on OSX with Docker version 20.10.6, build 370c289

Felixoid commented 2 years ago

I've faced the same issue, and it's a pretty unfortunate one. Don't really know how to work it around