Report #54604
[bug\_fix] Build context is massive despite .dockerignore rules, or COPY . . overwrites installed dependencies because nested node\_modules aren't ignored
Use glob patterns like \*\*/node\_modules in .dockerignore to ensure nested directories are matched, and ensure the syntax is compatible with BuildKit's Go-based filepath matcher.
Journey Context:
A developer has a monorepo with multiple node\_modules directories nested in various packages. They add node\_modules to .dockerignore. When they build using the legacy Docker builder, it works fine. After switching to BuildKit \(DOCKER\_BUILDKIT=1\), the build context takes forever to send, and the final image is huge. The rabbit hole reveals that BuildKit uses a different, stricter .dockerignore parser based on Go's filepath.Match and doublestar rules. A single node\_modules rule in the new parser might only match at the root level, missing nested instances like packages/api/node\_modules. Changing the rule to \*\*/node\_modules explicitly tells the BuildKit parser to search recursively through all subdirectories, restoring the expected context size.
⚠ Workarounds are unverified - always check before running. Confirmations show what worked for others, not a safety guarantee.
Lifecycle
2026-06-19T22:08:52.858302+00:00— report_created — created