dagger/dagger · error

service container is nil

Error message

service container is nil

What it means

After the service container is attached and evaluated, its underlying *Container self value is nil, so startContainer cannot derive exec metadata. This guards against evaluating a container that resolved to nothing.

Source

Thrown at core/service.go:580

	srv := dagql.CurrentDagqlServer(ctx)
	if srv == nil {
		return fmt.Errorf("failed to get dagql server")
	}
	attachedAny, err := cacheCtr.AttachResult(ctx, clientMetadata.SessionID, srv, svc.Container)
	if err != nil {
		return fmt.Errorf("attach service container: %w", err)
	}
	attached, ok := attachedAny.(dagql.ObjectResult[*Container])
	if !ok {
		return fmt.Errorf("attach service container: expected %T, got %T", svc.Container, attachedAny)
	}
	svc.Container = attached
	if err := cacheCtr.Evaluate(ctx, svc.Container); err != nil {
		return err
	}
	ctr := svc.Container.Self()
	if ctr == nil {
		return fmt.Errorf("service container is nil")
	}

	execMD := svc.ExecMD
	if execMD == nil {
		execMD, err = ctr.execMeta(ctx, ContainerExecOpts{
			ExperimentalPrivilegedNesting: svc.ExperimentalPrivilegedNesting,
			NoInit:                        svc.NoInit,
		}, nil, svc.ModuleContext)
		if err != nil {
			return err
		}
	} else {
		cloned := *execMD
		execMD = &cloned
	}

	query, err := CurrentQuery(ctx)
	if err != nil {

View on GitHub (pinned to 82ba2681db)

Solutions

  1. Retry the service start
  2. Ensure the Service comes from a real Container.AsService() call in your module code
  3. Report to Dagger maintainers with the trace if it reproduces
  4. Upgrade CLI/engine to align versions
Defensive patterns

Strategy: type-guard

Validate before calling

// ensure the Service is built from a materialized container
ctr := containerFrom(ctx, mod)
svc := ctr.WithExec([...]).AsService()

Type guard

func hasSelf(c dagql.ObjectResult[*Container]) bool {
    return c != nil && c.Self() != nil
}

Try / catch

if err := startService(ctx, svc); err != nil {
    if err.Error() == "service container is nil" {
        // rebuild the Service from a fresh container and retry
    }
    return err
}

Prevention

When it happens

Trigger: cacheCtr.Evaluate(ctx, svc.Container) succeeds but svc.Container.Self() returns nil — the container object exists in the dagql cache but its backing self value was never populated or was garbage-collected.

Common situations: A Service was constructed/serialized without a materialized container, e.g. a module returned a Service whose container came from a failed or stubbed evaluation, or internal cache eviction between attach and evaluate.

Related errors


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