dagger/dagger · error

failed to mount parent directory: %w

Error message

failed to mount parent directory: %w

What it means

WithDirectoryDockerfileCompat mounts the parent directory's snapshot read-only (via MountRefCloser) so ownership can be resolved against it and dest-path existence checked. If mounting that cached snapshot ref into the host fails (overlay/mount/underlying storage error), the error is wrapped as 'failed to mount parent directory'.

Source

Thrown at core/directory.go:2376

		return fmt.Errorf("failed to get source directory ref: %w", err)
	}

	query, err := CurrentQuery(ctx)
	if err != nil {
		return fmt.Errorf("failed to get current query: %w", err)
	}
	destDirTrailingSlash := strings.HasSuffix(destDir, "/") || strings.HasSuffix(destDir, "/.")
	destDir = path.Join(ourDir, destDir)
	if destDirTrailingSlash && !strings.HasSuffix(destDir, "/") {
		destDir += "/"
	}

	var parentRoot string
	var releaseParent func() error
	if dirRef != nil {
		parentRoot, _, releaseParent, err = MountRefCloser(ctx, dirRef, mountRefAsReadOnly)
		if err != nil {
			return fmt.Errorf("failed to mount parent directory: %w", err)
		}
		defer releaseParent()
	}

	newRef, err := query.SnapshotManager().New(
		ctx,
		dirRef,
		bkcache.WithRecordType(bkclient.UsageRecordTypeRegular),
		bkcache.WithDescription("Directory.withDirectoryDockerfileCompat"),
	)
	if err != nil {
		return fmt.Errorf("snapshotmanager.New failed: %w", err)
	}
	defer newRef.Release(context.WithoutCancel(ctx))

	var usage snapshots.Usage
	if err := MountRef(ctx, newRef, func(copyDest string, destMnt *mount.Mount) error {
		var ownership *Ownership

View on GitHub (pinned to 82ba2681db)

Solutions

  1. Check the engine host has mount support (FUSE/overlayfs permitted; not a heavily sandboxed container) and that /var/lib/dagger has free disk space.
  2. Clear the engine cache (dagger engine prune or restart engine) in case a cached snapshot ref is corrupted.
  3. Upgrade the Dagger engine to the latest version; if it persists, file an issue with the wrapped error and trace.

Example fix

// no code fix; host remediation example
// before: engine inside unprivileged container without fuse
// after: run engine with --privileged or on a host with FUSE enabled
Defensive patterns

Strategy: retry

Validate before calling

// Host checks before running the pipeline
cmd := exec.Command("sh", "-c", "df --output=avail -k /var/lib/dagger | tail -1")
out, _ := cmd.Output()
if kb, _ := strconv.Atoi(strings.TrimSpace(string(out))); kb < 1_000_000 {
    log.Fatal("not enough free space for Dagger engine snapshot mounts")
}

Try / catch

var serr *fs.PathError
if errors.As(err, &serr) && strings.Contains(err.Error(), "failed to mount parent directory") {
    // restart engine / prune cache, then retry once
    restartEngine(); return retry(op)
}

Prevention

When it happens

Trigger: Calling Directory.withDirectory with Dockerfile compat when dirRef is non-nil and the engine's snapshot mount (OverlayFS/ FuseFS or containerd mount) fails for the parent directory ref — typically disk, permissions, or mount-support issues on the host.

Common situations: Running the Dagger engine on hosts without proper mount support (restricted containers, missing /dev/fuse, seccomp blocking mount syscalls), full disk, or corrupted cache data under /var/lib/dagger.

Related errors


AI-assisted analysis of dagger/dagger@82ba2681db (2026-09-05). Data as JSON: /api/errors/e554bfb68e647ff6. Report an issue: GitHub.