{"record":{"id":"0c30608740f9747c","repo":"microsoft/aspire","slug":"failed-to-create-buildkit-instance-buildername-with-exit","errorCode":null,"errorMessage":"Failed to create buildkit instance '{builderName}' with exit code {processResult.ExitCode}.","messagePattern":"Failed to create buildkit instance '(.+?)' with exit code (.+?)\\.","errorType":"exception","errorClass":"ProcessFailedException","httpStatus":null,"severity":"error","filePath":"src/Aspire.Hosting/Publishing/DockerContainerRuntime.cs","lineNumber":207,"sourceCode":"        {\n            return false;\n        }\n    }\n\n    private async Task CreateBuildkitInstanceAsync(string builderName, CancellationToken cancellationToken)\n    {\n        var arguments = $\"buildx create --name \\\"{builderName}\\\" --driver docker-container\";\n        var processResult = await ExecuteContainerCommandWithResultAsync(\n            arguments,\n            \"Failed to create buildkit instance {BuilderName} with exit code {ExitCode}.\",\n            \"Successfully created buildkit instance {BuilderName}.\",\n            cancellationToken,\n            new object[] { builderName },\n            retainOutput: true).ConfigureAwait(false);\n\n        if (processResult.ExitCode != 0)\n        {\n            throw new ProcessFailedException(\n                $\"Failed to create buildkit instance '{builderName}' with exit code {processResult.ExitCode}.\",\n                processResult.ExitCode,\n                processResult.ProcessOutput,\n                processResult.TotalProcessOutputLineCount);\n        }\n    }\n\n    private async Task<int> RemoveBuildkitInstanceAsync(string builderName, CancellationToken cancellationToken)\n    {\n        var arguments = $\"buildx rm \\\"{builderName}\\\"\";\n\n        return await ExecuteContainerCommandWithExitCodeAsync(\n            arguments,\n            \"Failed to remove buildkit instance {BuilderName} with exit code {ExitCode}.\",\n            \"Successfully removed buildkit instance {BuilderName}.\",\n            cancellationToken,\n            new object[] { builderName }).ConfigureAwait(false);\n    }","sourceCodeStart":189,"sourceCodeEnd":225,"githubUrl":"https://github.com/microsoft/aspire/blob/25830f84bd145686607ad00c057b3f84e2e51d43/src/Aspire.Hosting/Publishing/DockerContainerRuntime.cs#L189-L225","documentation":"For OCI-format builds, DockerContainerRuntime creates a dedicated buildx builder instance (CreateBuildkitInstanceAsync). If the 'docker buildx create' command exits non-zero, the runtime throws ProcessFailedException including the builder name, exit code, and retained process output.","triggerScenarios":"RunDockerBuildAsync with ImageFormat == Oci triggers CreateBuildkitInstanceAsync; the underlying 'docker buildx create' process exits non-zero due to daemon unavailability, invalid builder name, buildx/BuildKit incompatibility, or permissions issues talking to the Docker daemon.","commonSituations":"Docker daemon not running while buildx plugin check passed; containerd storage/snapshotter conflicts; restricted CI environments blocking builder creation; stale/corrupt builder state with the same name.","solutions":["Check the ProcessOutput on the exception for the docker buildx create error message.","Ensure the Docker daemon is running ('docker info') before building.","Remove any conflicting builder: 'docker buildx rm <name>-builder' then retry.","Upgrade docker-buildx-plugin if the BuildKit instance creation is failing due to version incompatibility."],"exampleFix":"// before: retry fails with stale builder of same name\n// after: clean up builders before OCI build\ndocker buildx rm myapp-builder || true\ndocker builder prune -f","handlingStrategy":"retry","validationCode":"var info = System.Diagnostics.Process.Start(new System.Diagnostics.ProcessStartInfo(\"docker\", \"info\") { RedirectStandardOutput = true });\nif (info is null || !info.WaitForExit(5000) || info.ExitCode != 0)\n{\n    throw new InvalidOperationException(\"Docker daemon is not reachable; buildkit instance creation will fail.\");\n}","typeGuard":null,"tryCatchPattern":"try\n{\n    await runtime.BuildImageAsync(ctx, dockerfile, options, args, secrets, stage, ct);\n}\ncatch (ProcessFailedException ex) when (ex.Message.Contains(\"buildkit instance\"))\n{\n    logger.LogError(ex, \"Buildkit creation failed:\\n{Output}\", ex.ProcessOutput);\n    throw;\n}","preventionTips":["Ensure the Docker daemon is running before OCI builds.","Clean up stale builders (docker buildx rm) after failed builds.","Keep the buildx plugin updated to match the installed engine."],"tags":["docker","buildkit","image-build","process-failure"],"backgroundTag":"http-error-response","analyzedSha":"25830f84bd145686607ad00c057b3f84e2e51d43","analyzedAt":"2026-09-16T11:10:06.193Z","contentChangedAt":"2026-09-16T11:10:06.193Z","schemaVersion":2},"datasetVersion":"2026-09-21T04:17:39.646Z"}