GoogleContainerTools/skaffold · error

creating docker context: %w

Error message

creating docker context: %w

What it means

Wraps any failure from docker.CreateDockerTarContext, which builds the tar archive of the build context sent to the Docker daemon. The writer pipe is closed with this error so io.Copy surfaces it; it means the build context could not be created (bad Dockerfile path, missing files, unreadable .dockerignore patterns, or image name issues).

Source

Thrown at pkg/skaffold/diagnose/diagnose.go:157

	return timeutil.Humanize(time.Since(start)), err
}

func timeToComputeMTimes(deps []string) (string, error) {
	start := time.Now()

	if _, err := filemon.Stat(func() ([]string, error) { return deps, nil }); err != nil {
		return "nil", fmt.Errorf("computing modTimes: %w", err)
	}
	return timeutil.Humanize(time.Since(start)), nil
}

func sizeOfDockerContext(ctx context.Context, a *latest.Artifact, cfg docker.Config) (int64, error) {
	buildCtx, buildCtxWriter := io.Pipe()
	go func() {
		err := docker.CreateDockerTarContext(ctx, buildCtxWriter, docker.NewBuildConfig(
			a.Workspace, a.ImageName, a.DockerArtifact.DockerfilePath, nil), cfg)
		if err != nil {
			buildCtxWriter.CloseWithError(fmt.Errorf("creating docker context: %w", err))
			return
		}
		buildCtxWriter.Close()
	}()

	return io.Copy(io.Discard, buildCtx)
}

View on GitHub (pinned to a1189de023)

Solutions

  1. Verify the Dockerfile path in the artifact config is relative to the workspace and the file exists
  2. Run with --v.Debug and check the wrapped inner error (io.Copy error side) for the real cause
  3. Check .dockerignore for invalid syntax that makes context creation fail
  4. Ensure all files in the workspace are readable by the current user

Example fix

// before
buildctx:
  path: ./deploy/Dockerfile   # outside workspace
// after
build:
  artifacts:
    - image: myimg
      context: ./deploy
      docker:
        dockerfile: Dockerfile  # inside context dir
Defensive patterns

Strategy: try-catch

Validate before calling

func dockerfileExists(ws, df string) error {
  p, err := filepath.Abs(filepath.Join(ws, df))
  if err != nil { return err }
  fi, err := os.Stat(p)
  if err != nil { return err }
  if fi.IsDir() { return fmt.Errorf("%s is a directory", p) }
  return nil
}

Try / catch

n, err := sizeOfDockerContext(ctx, artifact, cfg)
if err != nil {
  var pathErr *fs.PathError
  if errors.As(err, &pathErr) {
    log.Printf("build context file problem: %v", pathErr)
  }
  return fmt.Errorf("cannot measure context: %w", err)
}

Prevention

When it happens

Trigger: sizeOfDockerContext called during diagnose; CreateDockerTarContext fails because the Dockerfile path is wrong, workspace files are missing/unreadable, the image name is invalid, or the .dockerignore is malformed.

Common situations: Dockerfile not present in the artifact workspace; Dockerfile outside the workspace context; symlinked or permission-denied files referenced by the context; malformed .dockerignore exclude patterns.

Related errors


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