{"record":{"id":"d508c6253b288ee0","repo":"dagger/dagger","slug":"failed-to-start-container-w","errorCode":null,"errorMessage":"failed to start container: %w","messagePattern":"failed to start container: %w","errorType":"exception","errorClass":null,"httpStatus":null,"severity":"error","filePath":"engine/client/drivers/container.go","lineNumber":267,"sourceCode":"\t\t}\n\t\t// run the container using that id in the name\n\t\tcontainerName = containerNamePrefix + id\n\t}\n\n\tleftoverEngines, err := d.collectLeftoverEngines(ctx, containerName)\n\tif err != nil {\n\t\tif errors.Is(err, context.Canceled) {\n\t\t\treturn nil, err\n\t\t}\n\t\tslog.Warn(\"failed to list containers\", \"error\", err)\n\t\tleftoverEngines = []string{}\n\t}\n\n\tfor i, leftoverEngine := range leftoverEngines {\n\t\t// if we already have a container with that name, attempt to start it\n\t\tif leftoverEngine == containerName {\n\t\t\tif err := d.backend.ContainerStart(ctx, leftoverEngine); err != nil {\n\t\t\t\treturn nil, fmt.Errorf(\"failed to start container: %w\", err)\n\t\t\t}\n\t\t\td.garbageCollectEngines(ctx, opts.cleanup, nil, slices.Delete(leftoverEngines, i, i+1))\n\t\t\treturn &url.URL{Host: containerName}, nil\n\t\t}\n\t}\n\n\t// ensure the image is pulled\n\texists, err := d.backend.ImageExists(ctx, opts.imageRef)\n\tif err != nil {\n\t\treturn nil, fmt.Errorf(\"failed to inspect image: %w\", err)\n\t}\n\tif !exists {\n\t\tif err := d.backend.ImagePull(ctx, opts.imageRef); err != nil {\n\t\t\treturn nil, fmt.Errorf(\"failed to pull image: %w\", err)\n\t\t}\n\t}\n\n\tvolume := distconsts.EngineDefaultStateDir","sourceCodeStart":249,"sourceCodeEnd":285,"githubUrl":"https://github.com/dagger/dagger/blob/82ba2681dbe30d3547a1dc50ea495900ab5b6047/engine/client/drivers/container.go#L249-L285","documentation":"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.","triggerScenarios":"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).","commonSituations":"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).","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"],"exampleFix":"// before (stale container won't start)\ndocker start dagger-engine-abcdef  # fails: image not found\n// after\ndocker rm -f dagger-engine-abcdef  # then re-run dagger, which provisions a new engine","handlingStrategy":"try-catch","validationCode":"engines, err := backend.ContainerLs(ctx)\nif err == nil && slices.Contains(engines, containerName) {\n    if err := backend.ContainerStart(ctx, containerName); err != nil {\n        backend.ContainerRemove(ctx, containerName) // allow fresh create\n    }\n}","typeGuard":null,"tryCatchPattern":"if err := backend.ContainerStart(ctx, name); err != nil {\n    _ = backend.ContainerRemove(ctx, name) // clear stale container\n    return nil, fmt.Errorf(\"failed to start container: %w\", err)\n}","preventionTips":["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)"],"tags":["container","docker","engine-startup"],"backgroundTag":"container-failed-to-start","analyzedSha":"82ba2681dbe30d3547a1dc50ea495900ab5b6047","analyzedAt":"2026-09-05T07:21:37.930Z","contentChangedAt":"2026-09-05T07:21:37.930Z","schemaVersion":2},"datasetVersion":"2026-09-12T12:17:11.808Z"}