docker/compose · error
error reading .dockerignore: %w
Error message
error reading .dockerignore: %w
What it means
readDockerignorePatterns feeds the .dockerignore stream into ignorefile.ReadAll, which parses the pattern list line by line. Malformed syntax (e.g. invalid character sequences, broken exclusion patterns) makes ReadAll return an error that is wrapped with this message. This path is used by the watch subsystem to build the path matcher from a live .dockerignore file.
Source
Thrown at pkg/watch/dockerignore.go:159
return p != "" && p[0] != '!' // Only keep exclusion patterns
})
}
pm, err := patternmatcher.New(absPatterns(absRoot, patterns))
if err != nil {
return nil, err
}
return &dockerPathMatcher{
repoRoot: absRoot,
matcher: pm,
}, nil
}
func readDockerignorePatterns(r io.Reader) ([]string, error) {
patterns, err := ignorefile.ReadAll(r)
if err != nil {
return nil, fmt.Errorf("error reading .dockerignore: %w", err)
}
return patterns, nil
}
func DockerIgnoreTesterFromContents(repoRoot string, contents string) (*dockerPathMatcher, error) {
patterns, err := ignorefile.ReadAll(strings.NewReader(contents))
if err != nil {
return nil, fmt.Errorf("error reading .dockerignore: %w", err)
}
return NewDockerPatternMatcher(repoRoot, patterns)
}
View on GitHub (pinned to ddc4b044b6)
Solutions
- Open .dockerignore and fix or delete the offending line — the wrapped error usually carries the line number/position.
- Validate locally: `docker build .` uses the same parser and will surface the same error quickly.
- If the file is mangled beyond repair, regenerate it from git: `git checkout -- .dockerignore`.
Example fix
# before (.dockerignore contains a malformed line) src/**/tmp garbage # after src/**/tmp
Defensive patterns
Strategy: validation
Validate before calling
// lint .dockerignore before starting a watch session
f, err := os.Open(".dockerignore")
if err == nil {
if _, err := ignorefile.ReadAll(f); err != nil {
log.Fatalf("invalid .dockerignore: %v", err)
}
} Prevention
- Keep .dockerignore under version control so corruption is visible in diffs.
- Run `docker build .` (same parser) as a quick syntax check after editing .dockerignore.
- Avoid editing .dockerignore with tools that can emit invalid UTF-8 or merge-conflict artifacts.
When it happens
Trigger: Starting a develop/watch session where the repo's .dockerignore contains lines the dockerignore parser rejects — typically patterns with illegal characters or truncated/corrupted lines (binary junk, CRLF mixed with unusual bytes, or an editor writing invalid UTF-8).
Common situations: A .dockerignore corrupted by a merge conflict or an editor that inserted garbage; copy-pasting patterns containing characters the dockerignore grammar does not accept; a file accidentally overwritten with binary content.
Related errors
- OCI remote resource is disabled by %q
- cannot watch root directory
- os.Stat(%q): %w
- newWatcher: %w
- notify.Add(%q): %w
AI-assisted analysis of docker/compose@ddc4b044b6 (2026-08-15).
Data as JSON: /api/errors/04e3d3b12ccbe0d8.
Report an issue: GitHub.