GoogleContainerTools/skaffold · error
listing copied files: %w
Error message
listing copied files: %w
What it means
extractCopyCommands walked the parsed (and OnBuild-expanded) instruction list to determine which files each COPY/ADD pulls in; when that fails — e.g. a stage referenced in COPY --from does not exist, or the instruction cannot be resolved against the build context — ReadCopyCmdsFromDockerfile wraps the failure with 'listing copied files'. Dependency computation aborts because the set of copied files cannot be determined.
Source
Thrown at pkg/skaffold/docker/parse.go:114
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)
if err != nil {
return nil, fmt.Errorf("listing copied files: %w", err)
}
return expandSrcGlobPatterns(workspace, cpCmds)
}
func ExtractOnlyCopyCommands(absDockerfilePath string) ([]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)
}
var copied []FromTo
workdir := "/"View on GitHub (pinned to a1189de023)
Solutions
- Ensure every COPY --from=<name> references a stage defined by an earlier FROM in the same Dockerfile
- Give each stage an explicit unique 'FROM image AS name' and fix typos in stage names
- Test with 'docker build .' — if docker itself rejects the stage reference, fix it the same way
- If the error comes from an ONBUILD parent image, inspect that image's Dockerfile history (docker inspect) and adjust your context accordingly
Example fix
// before FROM golang AS build FROM alpine COPY --from=buildr /app/bin /bin // after FROM golang AS build FROM alpine COPY --from=build /app/bin /bin
Defensive patterns
Strategy: validation
Validate before calling
func validateCopyFromStages(dockerfilePath string) error {
stages := map[string]bool{}
lines := readLines(dockerfilePath)
for _, l := range lines {
if m := fromStageRe.FindStringSubmatch(l); m != nil {
stages[strings.ToLower(m[1])] = true
}
if m := copyFromRe.FindStringSubmatch(l); m != nil && !stages[strings.ToLower(m[1])] {
return fmt.Errorf("COPY --from=%q references undefined stage", m[1])
}
}
return nil
} Type guard
func stageDefined(dockerfileContent, stage string) bool {
re := regexp.MustCompile(`(?i)^FROM\s+\S+\s+AS\s+(\S+)`)
for _, l := range strings.Split(dockerfileContent, "\n") {
if m := re.FindStringSubmatch(l); m != nil && strings.EqualFold(m[1], stage) {
return true
}
}
return false
} Try / catch
fts, err := skaffold.ReadCopyCmdsFromDockerfile(path, args, cfg, false)
if err != nil && strings.Contains(err.Error(), "listing copied files") {
return fmt.Errorf("check COPY --from stage names and FROM ordering: %w", err)
} Prevention
- Always name stages explicitly (FROM x AS name) and reference only defined names
- Run 'docker build .' before Skaffold — it reports bad stage references too
- Grep for 'COPY --from' after any stage rename to catch stale references
- Inspect ONBUILD parent images (docker inspect) to know what instructions they inject
When it happens
Trigger: ReadCopyCmdsFromDockerfile invoked on a Dockerfile whose COPY --from=<stage> references a nonexistent stage, whose multi-stage FROM names are duplicated/invalid, or where an instruction needed for copy extraction is malformed after build-arg/ONBUILD expansion.
Common situations: Renaming a build stage but forgetting to update COPY --from references; ONBUILD parent images introducing COPY instructions that reference missing context; complex multi-stage files where a stage is referenced before it is defined.
Related errors
- normalizing dockerfile path: %w
- reading dockerfile: %w
- removing unused default args: %w
- normalizing dockerfilePath path: %w
- docker build failure: %w
AI-assisted analysis of GoogleContainerTools/skaffold@a1189de023 (2026-09-05).
Data as JSON: /api/errors/15781ae0506cca04.
Report an issue: GitHub.