slimtoolkit/slim · error

Error reading .dockerignore: %v

Error message

Error reading .dockerignore: %v

What it means

readPatterns (called by dockerignore.Load) scans a .dockerignore file; scanner.Err() reports any I/O or decoding failure encountered while reading. The error wraps the underlying scanner error, meaning the .dockerignore exists but could not be read (permissions, I/O error, invalid encoding).

Source

Thrown at pkg/docker/dockerignore/dockerignore.go:122

		invert := pattern[0] == '!'
		if invert {
			pattern = strings.TrimSpace(pattern[1:])
		}
		if len(pattern) > 0 {
			pattern = filepath.Clean(pattern)
			pattern = filepath.ToSlash(pattern)
			if len(pattern) > 1 && pattern[0] == '/' {
				pattern = pattern[1:]
			}
		}
		if invert {
			pattern = "!" + pattern
		}

		excludes = append(excludes, pattern)
	}
	if err := scanner.Err(); err != nil {
		return nil, fmt.Errorf("Error reading .dockerignore: %v", err)
	}
	return excludes, nil
}

//Docker's pattern matching

type patternMatcher struct {
	patterns   []*pattern
	exclusions bool
}

func newPatternMatcher(patterns []string) (*patternMatcher, error) {
	pm := &patternMatcher{
		patterns: make([]*pattern, 0, len(patterns)),
	}
	for _, p := range patterns {
		// Eliminate leading and trailing whitespace.
		p = strings.TrimSpace(p)

View on GitHub (pinned to 81940d17fa)

Solutions

  1. Check file permissions on .dockerignore (chmod 644) and ensure the process user can read it.
  2. Confirm the path is a regular file, not a directory or broken symlink, and re-create the file if it is corrupt.
  3. Fix the underlying I/O issue (disk full, network mount failure) indicated by the wrapped %v detail, then retry.

Example fix

// before
-rw------- .dockerignore  (owned by root, build runs as ci)
// after
chmod 644 .dockerignore
Defensive patterns

Strategy: validation

Validate before calling

fi, err := os.Stat(dockerignorePath)
if err != nil || fi.IsDir() {
	return fmt.Errorf(".dockerignore missing or not a file")
}
f, err := os.Open(dockerignorePath)
if err != nil { return err }
if _, err := f.Read(make([]byte, 1)); err != nil {
	return fmt.Errorf(".dockerignore unreadable: %w", err)
}
f.Close()

Try / catch

excludes, err := dockerignore.Load(path)
if err != nil && strings.Contains(err.Error(), "Error reading .dockerignore") {
	return fmt.Errorf("build context unusable: %w", err)
}

Prevention

When it happens

Trigger: Calling dockerignore.Load (via readPatterns) on a .dockerignore file that is unreadable: permission denied mid-read, file replaced/deleted between open and scan, I/O device error, or invalid (non-UTF-8) bytes causing scanner failure.

Common situations: CI runners where the workspace .dockerignore has restrictive permissions; a .dockerignore that is a directory or a broken symlink opened then failing on read; rootless builds hitting permission issues after checkout with umask problems.

Understand the failure class

Background: "failed to read file", EACCES, ENOENT and "could not read <path>" errors: when a program can't read a file from disk — this error's family across 49 libraries.

Related errors


AI-assisted analysis of slimtoolkit/slim@81940d17fa (2026-08-31). Data as JSON: /api/errors/d69d41deeba51d05. Report an issue: GitHub.