Skip to content

Better error message if file/directory is ignored #5826

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

Open
rumpl opened this issue Mar 10, 2025 · 2 comments
Open

Better error message if file/directory is ignored #5826

rumpl opened this issue Mar 10, 2025 · 2 comments

Comments

@rumpl
Copy link
Member

rumpl commented Mar 10, 2025

Description

With this .dockerignore file:

file

And this Dockerfile:

FROM scratch
COPY file .

When I try to build the image I get this error:

$ docker build -t test .
[+] Building 0.0s (4/4) FINISHED                                                                                                      docker:desktop-linux
 => [internal] load build definition from Dockerfile                                                                                                  0.0s
 => => transferring dockerfile: 62B                                                                                                                   0.0s
 => [internal] load .dockerignore                                                                                                                     0.0s
 => => transferring context: 45B                                                                                                                      0.0s
 => [internal] load build context                                                                                                                     0.0s
 => => transferring context: 2B                                                                                                                       0.0s
 => ERROR [1/1] COPY file .                                                                                                                           0.0s
------
 > [1/1] COPY file .:
------
Dockerfile:2
--------------------
   1 |     FROM scratch
   2 | >>> COPY file .
   3 |
--------------------
ERROR: failed to solve: failed to compute cache key: failed to calculate checksum of ref 30f4015d-0523-4ca8-b16b-d9d2abbc1430::aseapibm7ur3dq8lk8gjdig46: "/file": not found

It would be great is the error said something about the file being ingored by the .dockerignore file.

@crazy-max
Copy link
Member

crazy-max commented Mar 10, 2025

The following check https://docs.docker.com/reference/build-checks/copy-ignored-file/ should warn about the file being ignored. @tonistiigi Do you recall why we have this check behind experimental?

But I agree that we should add complementary info in build error if this file is actually being ignored like:

"/file": not found (ignored)

@crazy-max
Copy link
Member

I see we set IncludePatterns and don't set ExcludePatterns during frontend convert:

opts := append([]llb.CopyOption{&llb.CopyInfo{
Mode: chopt,
FollowSymlinks: true,
CopyDirContentsOnly: true,
IncludePatterns: patterns,
AttemptUnpack: cfg.isAddCommand,
CreateDestPath: true,
AllowWildcard: true,
AllowEmptyWildcard: true,
}}, copyOpt...)
and so defer to LLB which will return not found. If we set ExcludePatterns we could then check on LLB side if the file is actually ignored and return a better error message.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

2 participants