GoogleContainerTools/skaffold · error

invalid dockerfile instruction: %q

Error message

invalid dockerfile instruction: %q

What it means

Fires in readCopyCommand when a COPY/ADD instruction in the Dockerfile has no source path arguments to expand (the node's value list is empty or only flags). The instruction is considered malformed because a valid COPY needs at least a src and dest.

Source

Thrown at pkg/skaffold/docker/parse.go:344

func readCopyCommand(value *parser.Node, envs []string, workdir string) (*copyCommand, error) {
	// If the --from flag is provided, we are dealing with a multi-stage dockerfile
	// Adding a dependency from a different stage does not imply a source dependency
	if hasMultiStageFlag(value.Flags) {
		return nil, nil
	}

	var paths []string
	slex := shell.NewLex('\\')
	for value := value.Next; value != nil && !strings.HasPrefix(value.Value, "#"); value = value.Next {
		path, _, err := slex.ProcessWord(value.Value, shell.EnvsFromSlice(envs))
		if err != nil {
			return nil, fmt.Errorf("expanding src: %w", err)
		}

		paths = append(paths, path)
	}
	if len(paths) == 0 {
		return nil, fmt.Errorf("invalid dockerfile instruction: %q", value.Original)
	}

	// All paths are sources except the last one
	var srcs []string
	for _, src := range paths[0 : len(paths)-1] {
		if hasOneOfPrefixes(src, []string{"http://", "https://", "<<"}) {
			log.Entry(context.TODO()).Debugln("Skipping watch on remote/heredoc dependency", src)
			continue
		}

		srcs = append(srcs, src)
	}

	// Destination is last
	dest := paths[len(paths)-1]
	destIsDir := strings.HasSuffix(dest, "/") || path.Base(dest) == "." || path.Base(dest) == ".."
	dest = resolveDir(workdir, dest)

View on GitHub (pinned to a1189de023)

Solutions

  1. Fix the COPY/ADD instruction to include both source and destination arguments
  2. Remove stray COPY instructions with missing arguments
  3. Ensure multi-line/instruction continuation formatting is correct
Defensive patterns

Strategy: validation

When it happens

Trigger: Thrown at pkg/skaffold/docker/parse.go:344 when the library encounters an invalid state.

Common situations: See trigger scenarios.


AI-assisted analysis of GoogleContainerTools/skaffold@a1189de023 (2026-09-05). Data as JSON: /api/errors/db30b90d9ccd2aed. Report an issue: GitHub.