wagoodman/dive · critical

cannot build image: %w

Error message

cannot build image: %w

What it means

Returned by `dive build` when the underlying container engine fails to build the image from the given Dockerfile arguments. dive build is a thin wrapper over docker/podman build: the args slice is forwarded verbatim, so this error wraps whatever the engine's build API returned — Dockerfile syntax errors, missing build context, failed RUN steps, network failures during pulls.

Source

Thrown at cmd/dive/cli/internal/command/build.go:40

	return app.SetupCommand(&cobra.Command{
		Use:                "build [any valid `docker build` arguments]",
		Short:              "Builds and analyzes a docker image from a Dockerfile (this is a thin wrapper for the `docker build` command).",
		DisableFlagParsing: true,
		RunE: func(cmd *cobra.Command, args []string) error {
			if err := setUI(app, opts.Application); err != nil {
				return fmt.Errorf("failed to set UI: %w", err)
			}

			resolver, err := dive.GetImageResolver(opts.Analysis.Source)
			if err != nil {
				return fmt.Errorf("cannot determine image provider for build: %w", err)
			}

			ctx := cmd.Context()

			img, err := adapter.ImageResolver(resolver).Build(ctx, args)
			if err != nil {
				return fmt.Errorf("cannot build image: %w", err)
			}

			return run(cmd.Context(), opts.Application, img, resolver)
		},
	}, opts)
}

View on GitHub (pinned to d6c691947f)

Solutions

  1. Read the wrapped error — it contains the engine's own build log line that failed
  2. Reproduce outside dive first (docker build <same args>) and fix the Dockerfile/step it points to
  3. Verify the build context path and Dockerfile name match what you passed
  4. Fix network/registry access if the failure is a base-image pull (proxy, auth via docker login)

Example fix

# before
FROM alpine
RUN exit 1   # dive build fails here

# after
FROM alpine
RUN echo ok
Defensive patterns

Strategy: try-catch

Validate before calling

# validate the build works before wrapping it with dive
docker build -t probe/context . || exit 1   # cheap pre-check
dive build .

Try / catch

img, err := adapter.ImageResolver(resolver).Build(ctx, args)
if err != nil {
    // wrapped text contains the engine's own failing step; surface it verbatim for the user
    return fmt.Errorf("cannot build image: %w", err)
}

Prevention

When it happens

Trigger: adapter.ImageResolver(resolver).Build(ctx, args) with args like '.' pointing at a context with a broken Dockerfile; RUN steps that exit non-zero; FROM referencing an untaggable/unpullable image; invalid flags passed through because DisableFlagParsing is set.

Common situations: Running dive build . on a Dockerfile that does not yet build cleanly; CI checkout missing the build context directory; a base image pull failing behind a corporate proxy; passing docker build flags dive forwards verbatim.

Related errors


AI-assisted analysis of wagoodman/dive@d6c691947f (2026-08-15). Data as JSON: /api/errors/940c6c57ca02af04. Report an issue: GitHub.