{"record":{"id":"a98649c1c9d67594","repo":"hashicorp/nomad","slug":"failed-to-create-exec-object-v-a98649","errorCode":null,"errorMessage":"failed to create exec object: %v","messagePattern":"failed to create exec object: (.+?)","errorType":"exception","errorClass":null,"httpStatus":null,"severity":"error","filePath":"drivers/docker/handle.go","lineNumber":97,"sourceCode":"\t\ts.ReattachConfig = pstructs.ReattachConfigFromGoPlugin(h.dloggerPluginClient.ReattachConfig())\n\t}\n\treturn s\n}\n\nfunc (h *taskHandle) Exec(ctx context.Context, cmd string, args []string) (*drivers.ExecTaskResult, error) {\n\tfullCmd := make([]string, len(args)+1)\n\tfullCmd[0] = cmd\n\tcopy(fullCmd[1:], args)\n\tcreateExecOpts := mclient.ExecCreateOptions{\n\t\tAttachStdin:  false,\n\t\tAttachStdout: true,\n\t\tAttachStderr: true,\n\t\tTTY:          false,\n\t\tCmd:          fullCmd,\n\t}\n\texec, err := h.dockerClient.ExecCreate(ctx, h.containerID, createExecOpts)\n\tif err != nil {\n\t\treturn nil, fmt.Errorf(\"failed to create exec object: %v\", err)\n\t}\n\n\texecResult := &drivers.ExecTaskResult{ExitResult: &drivers.ExitResult{}}\n\tstdout, _ := circbuf.NewBuffer(int64(drivers.CheckBufSize))\n\tstderr, _ := circbuf.NewBuffer(int64(drivers.CheckBufSize))\n\tstartOpts := mclient.ExecAttachOptions{TTY: false}\n\n\t// hijack exec output streams\n\thijacked, err := h.dockerClient.ExecAttach(ctx, exec.ID, startOpts)\n\tif err != nil {\n\t\treturn nil, fmt.Errorf(\"failed to attach to exec object: %w\", err)\n\t}\n\n\t_, err = stdcopy.StdCopy(stdout, stderr, hijacked.Reader)\n\tif err != nil {\n\t\treturn nil, err\n\t}\n\tdefer hijacked.Close()","sourceCodeStart":79,"sourceCodeEnd":115,"githubUrl":"https://github.com/hashicorp/nomad/blob/482b49bf1aec006f089bcfc7e632d8f6ac303e5e/drivers/docker/handle.go#L79-L115","documentation":"During drivers.ExecTask, the handle first creates a Docker exec instance inside the running container via ExecCreate. If the Docker Engine API rejects that call, the driver wraps the failure as 'failed to create exec object'. Nothing was executed; this is a setup-stage failure before attach or output capture.","triggerScenarios":"h.dockerClient.ExecCreate(ctx, h.containerID, createExecOpts) returns an error: container no longer running/removed, invalid command slice, Docker daemon unreachable, or API permission denied (e.g. non-root user without exec privileges).","commonSituations":"nomad alloc exec run against a dead/exited task; container was garbage-collected between list and exec; Docker daemon restarted or socket permissions changed; Docker API version mismatch between the plugin's client and the engine.","solutions":["Verify the task/container is running ('docker ps', 'nomad alloc status') before exec; restart the task if it exited.","Check Docker daemon health and socket permissions on the host (systemctl status docker, /var/run/docker.sock access).","Confirm the Docker API version used by the nomad docker driver is compatible with the engine (API version negotiation/mismatch).","Retry the exec; transient daemon errors often resolve after the engine recovers."],"exampleFix":"// before: exec on possibly-stopped allocation\nnomad alloc exec <alloc> <cmd>\n// after: guard by checking task state first\nnomad alloc status <alloc>   # ensure task is 'running'\nnomad alloc exec <alloc> <cmd>","handlingStrategy":"retry","validationCode":"// check the allocation's task state before exec\n// nomad alloc status <alloc> -> task state must be 'running'","typeGuard":null,"tryCatchPattern":"for i := 0; i < 3; i++ {\n    res, err := driver.ExecTask(ctx, taskID, opts)\n    if err == nil {\n        break\n    }\n    if strings.Contains(err.Error(), \"failed to create exec object\") {\n        time.Sleep(2*time.Second)\n        continue\n    }\n    return err\n}","preventionTips":["Verify task health before issuing exec commands.","Monitor Docker daemon health on Nomad clients.","Keep docker driver and engine API versions compatible."],"tags":["docker-driver","exec","docker-api"],"backgroundTag":"docker-exec-create-failed","analyzedSha":"482b49bf1aec006f089bcfc7e632d8f6ac303e5e","analyzedAt":"2026-09-04T07:54:14.808Z","contentChangedAt":"2026-09-04T07:54:14.808Z","schemaVersion":2},"datasetVersion":"2026-09-08T10:18:20.063Z"}