GoogleContainerTools/skaffold · error
parsing dockerfile %q: %w
Error message
parsing dockerfile %q: %w
What it means
ReadCopyCmdsFromDockerfile wraps any error returned by the BuildKit dockerfile parser (parser.Parse) with the absolute path of the Dockerfile it tried to parse. It means the Dockerfile text is syntactically invalid per the Dockerfile grammar, so Skaffold cannot extract COPY commands to compute build dependencies. The wrapped inner error from moby/buildkit names the line and specific syntax problem.
Source
Thrown at pkg/skaffold/docker/parse.go:94
endLine int
}
var (
// RetrieveImage is overridden for unit testing
RetrieveImage = retrieveImage
)
// ReadCopyCmdsFromDockerfile parses a given dockerfile for COPY commands accounting for build args, env vars, globs, etc
// and returns an array of FromTos specifying the files that will be copied 'from' local dirs 'to' container dirs in the COPY statements
func ReadCopyCmdsFromDockerfile(ctx context.Context, onlyLastImage bool, absDockerfilePath, workspace string, buildArgs map[string]*string, cfg Config) ([]FromTo, error) {
r, err := os.ReadFile(absDockerfilePath)
if err != nil {
return nil, err
}
res, err := parser.Parse(bytes.NewReader(r))
if err != nil {
return nil, fmt.Errorf("parsing dockerfile %q: %w", absDockerfilePath, err)
}
if err := validateParsedDockerfile(bytes.NewReader(r), res); err != nil {
return nil, fmt.Errorf("parsing dockerfile %q: %w", absDockerfilePath, err)
}
dockerfileLines := res.AST.Children
if err := expandBuildArgs(dockerfileLines, buildArgs); err != nil {
return nil, fmt.Errorf("putting build arguments: %w", err)
}
dockerfileLinesWithOnbuild, err := expandOnbuildInstructions(ctx, dockerfileLines, cfg)
if err != nil {
return nil, err
}
cpCmds, err := extractCopyCommands(ctx, dockerfileLinesWithOnbuild, onlyLastImage, cfg)View on GitHub (pinned to a1189de023)
Solutions
- Run 'docker build --check .' or hadolint on the Dockerfile to see the exact line and fix the syntax error
- Verify the file at the path in the error message is the intended Dockerfile and is not truncated or corrupted
- Check for syntax requiring a newer parser (heredocs, # syntax= directive) and add the correct '# syntax=' header or simplify the instruction
- Regenerate the Dockerfile if it is produced by templating — the template output, not the template, is invalid
Example fix
// before RUN echo "unterminated // after RUN echo "terminated properly"
Defensive patterns
Strategy: try-catch
Validate before calling
func validateDockerfileSyntax(path string) error {
f, err := os.Open(path)
if err != nil { return err }
defer f.Close()
if _, err := parser.Parse(f); err != nil {
return fmt.Errorf("invalid Dockerfile %s: %w", path, err)
}
return nil
}
// call before invoking skaffold; also lint in CI: hadolint Dockerfile Type guard
func isParseableDockerfile(path string) bool {
f, err := os.Open(path)
if err != nil { return false }
defer f.Close()
_, perr := parser.Parse(f)
return perr == nil
} Try / catch
deps, err := skaffold.ReadCopyCmdsFromDockerfile(absPath, buildArgs, cfg, false)
if err != nil {
var syntaxErr *os.PathError
if errors.As(err, &syntaxErr) {
return fmt.Errorf("check dockerfile path: %w", err)
}
return fmt.Errorf("dockerfile syntax invalid; run 'docker build --check': %w", err)
} Prevention
- Lint every Dockerfile with hadolint or 'docker build --check' in CI before Skaffold runs
- Pin the '# syntax=' directive when using BuildKit-only features
- Keep Dockerfiles ASCII/LF; avoid editors that inject odd whitespace
- Never let template engines emit Dockerfiles unchecked — validate the rendered output
When it happens
Trigger: Calling any Skaffold API that reaches ReadCopyCmdsFromDockerfile (artifact dependency computation via getDependencies, getDependenciesByDockerCopyFromTo, SyncMap) when the Dockerfile at absDockerfilePath fails parser.Parse — e.g. malformed instructions, unterminated quotes, bad escape directive, invalid heredoc syntax.
Common situations: Hand-edited Dockerfiles with typos (missing FROM line, broken continuation characters); Dockerfiles written for newer syntax (heredocs, --mount flags) parsed with an older parser; CRLF or encoding corruption; an editor or template engine emitting invalid intermediate Dockerfile content.
Related errors
- removing unused default args: %w
- parsing dockerfile: %w
- parsing manifests file into manifest list object: %w
- parsing image name for registry: %w
- normalizing dockerfile path: %w
AI-assisted analysis of GoogleContainerTools/skaffold@a1189de023 (2026-09-05).
Data as JSON: /api/errors/3938d17527c8aab5.
Report an issue: GitHub.