dagger/dagger · error
container directory lazy: missing mounted directory source…
Error message
container directory lazy: missing mounted directory source for %s
What it means
While lazily materializing a directory view of a container mount, Dagger inspects each mount record. For a mount whose source is a Directory result (DirectorySource), it peeks the already-computed directory value; if the value is absent or nil at evaluation time the mount cannot be materialized and this error names the mount target path. It indicates the mounted directory was never evaluated or its result was lost (e.g. cache miss/corruption) before the container state was consumed.
Solutions
- Force evaluation of the mounted directory before building the container (e.g. call dir.entries() or export it) so its result is concrete
- Re-run in a fresh session to rebuild the DAG without persisted lazy state
- Restart/prune the engine cache to remove stale persisted results
- Check for upstream errors on the source directory (a failed dir computation can leave the source nil)
Example fix
// before
ctr := client.Container().From("alpine").WithMountedDirectory("/work", lazilyBuiltDir)
out := ctr.Directory("/work/out")
// after
if _, err := lazilyBuiltDir.Contents(ctx); err != nil { return err } // force evaluation first
ctr := client.Container().From("alpine").WithMountedDirectory("/work", lazilyBuiltDir) Defensive patterns
Strategy: validation
Validate before calling
// Ensure the mounted source directory is fully evaluated before mounting
if _, err := srcDir.Contents(ctx); err != nil { return err }
ctr := client.Container().From("alpine").WithMountedDirectory("/work", srcDir) Try / catch
d, err := ctr.Directory(ctx, "/work/out")
if err != nil && strings.Contains(err.Error(), "missing mounted directory source") {
// re-evaluate the source directory, rebuild container, retry
} Prevention
- Force-evaluate source directories (entries/contents/export) before withMountedDirectory
- Don't chain .directory() reads off containers built from cache-restored IDs
- Check upstream directory operations for errors before mounting them
- Keep engine cache healthy; prune after upgrades
When it happens
Trigger: Using container.directory(target) or listing files on a lazy container where a withMountedDirectory(target, dir) mount's Directory result cannot be Peeked when the lazy state is evaluated — typically after persisted-state replay where the directory was never forced.
Common situations: Module caching replaying a container built with mounted directories across engine restarts; passing a lazily-built directory that errored upstream; engine cache eviction/corruption dropping the mounted dir result.
Related errors
- container directory lazy: missing mounted directory path for
- container directory lazy: missing mounted directory…
- container directory lazy: nil parent container
- container directory lazy: nil resolved directory
- acquire operation lease
AI-assisted analysis of dagger/dagger@82ba2681db (2026-09-05).
Data as JSON: /api/errors/9ebb625ec0553079.
Report an issue: GitHub.
Appendix: source
Thrown at core/container.go:3288
if err := srv.Select(ctx, lazy.Parent, &rootfs, dagql.Selector{Field: "rootfs"}); err != nil {
return err
}
if subpath == "" || subpath == "." || subpath == "/" {
resolved = rootfs
} else {
if err := srv.Select(ctx, rootfs, &resolved, dagql.Selector{
Field: "directory",
Args: []dagql.NamedInput{
{Name: "path", Value: dagql.String(subpath)},
},
}); err != nil {
return err
}
}
case mnt.DirectorySource != nil:
mountedDir, ok := mnt.DirectorySource.Peek()
if !ok || mountedDir == nil {
return fmt.Errorf("container directory lazy: missing mounted directory source for %s", mnt.Target)
}
if subpath == "" || subpath == "." {
detached, err := cloneDetachedDirectoryForContainerResult(ctx, mountedDir)
if err != nil {
return err
}
dir.Platform = detached.Platform
dir.Services = slices.Clone(detached.Services)
if dirPath, ok := detached.Dir.Peek(); ok {
dir.Dir.setValue(dirPath)
}
if snapshot, ok := detached.Snapshot.Peek(); ok && snapshot != nil {
dir.Snapshot.setValue(snapshot)
}
dir.Lazy = nil
return nil
}
mountedDirPath, ok := mountedDir.Dir.Peek()View on GitHub (pinned to 82ba2681db)