dagger/dagger · error
failed to start container: %w
Error message
failed to start container: %w
What it means
This wrapped error is produced by the image driver's create method when a leftover engine container matching the target name exists but ContainerStart fails to start it. The %w wrapping preserves the underlying backend error (docker/podman start failure) for errors.Is/As inspection. It means the driver found an existing engine and tried to reuse it, but the runtime refused.
Source
Thrown at engine/client/drivers/container.go:267
}
// run the container using that id in the name
containerName = containerNamePrefix + id
}
leftoverEngines, err := d.collectLeftoverEngines(ctx, containerName)
if err != nil {
if errors.Is(err, context.Canceled) {
return nil, err
}
slog.Warn("failed to list containers", "error", err)
leftoverEngines = []string{}
}
for i, leftoverEngine := range leftoverEngines {
// if we already have a container with that name, attempt to start it
if leftoverEngine == containerName {
if err := d.backend.ContainerStart(ctx, leftoverEngine); err != nil {
return nil, fmt.Errorf("failed to start container: %w", err)
}
d.garbageCollectEngines(ctx, opts.cleanup, nil, slices.Delete(leftoverEngines, i, i+1))
return &url.URL{Host: containerName}, nil
}
}
// ensure the image is pulled
exists, err := d.backend.ImageExists(ctx, opts.imageRef)
if err != nil {
return nil, fmt.Errorf("failed to inspect image: %w", err)
}
if !exists {
if err := d.backend.ImagePull(ctx, opts.imageRef); err != nil {
return nil, fmt.Errorf("failed to pull image: %w", err)
}
}
volume := distconsts.EngineDefaultStateDirView on GitHub (pinned to 82ba2681db)
Solutions
- Remove the stale container (`docker rm -f <container>`) and let Provision create a fresh one
- Check `docker start <container>` manually to see the raw runtime error
- Restart the container daemon (Docker Desktop / podman service) if it is in a bad state
- Check disk space and image availability; `docker system prune` if disk pressure caused start failure
Example fix
// before (stale container won't start) docker start dagger-engine-abcdef # fails: image not found // after docker rm -f dagger-engine-abcdef # then re-run dagger, which provisions a new engine
Defensive patterns
Strategy: try-catch
Validate before calling
engines, err := backend.ContainerLs(ctx)
if err == nil && slices.Contains(engines, containerName) {
if err := backend.ContainerStart(ctx, containerName); err != nil {
backend.ContainerRemove(ctx, containerName) // allow fresh create
}
} Try / catch
if err := backend.ContainerStart(ctx, name); err != nil {
_ = backend.ContainerRemove(ctx, name) // clear stale container
return nil, fmt.Errorf("failed to start container: %w", err)
} Prevention
- Remove containers that fail to start so the next Provision creates a fresh engine
- Verify the image for the stopped container still exists locally before starting
- Keep the container runtime healthy (daemon up, disk space available)
When it happens
Trigger: create finds leftoverEngines containing exactly containerName and calls d.backend.ContainerStart(ctx, leftoverEngine), which returns a non-nil error (e.g. container is in a broken/removing state, runtime daemon unavailable, image missing for a stopped container).
Common situations: A stale engine container from a previous version whose image was pruned; container stuck in a restarting/exited state after a crash; Docker daemon partially responsive (exists in ls but cannot start).
Related errors
- failed to run container: %w
- container already exists
- install dnsmasq: %w
- install cni: %w
- mount does not exist
AI-assisted analysis of dagger/dagger@82ba2681db (2026-09-05).
Data as JSON: /api/errors/d508c6253b288ee0.
Report an issue: GitHub.