docker / buildx

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

Request: More practical defaults for .dockerignore #2756

Open mcandre opened 1 month ago

mcandre commented 1 month ago

Description

By default, docker builds should exclude common patterns from ADD / COPY directives:

thaJeztah commented 4 weeks ago

I'll transfer this ticket to the buildx repository, because it is related to docker build, which is now handled (by default) by buildx.

I'm not sure if changing the defaults would be possible though. While it's common for some scenarios to exclude certain files (e.g. the Dockerfile itself, or the .git directory), there are also many scenarios where these files are intentionally part of the build context. The .git directory in many scenarios may be used as part of builds to determined versions used; often this would be consumed through a RUN --mount ..., but currently mounting from a build-context also is restricted by .dockerignore.

There's some tickets related to .dockerignore; one epic that collects various related topics;

Which also has a linked ticket about supporting a global .dockerignore (which could allow defining your own "defaults");

However, defining a global ignore also comes with consequences; it can complicate debugging (why is a file missing from my build?), so may need additional features to expose what's ignored (something similar to git check ignore)