hashicorp/nomad · error

failed to create exec object: %v

Error message

failed to create exec object: %v

What it means

This error wraps a failure from the Docker API `ExecCreate` call, which registers an exec instance inside the running container and returns an exec ID. If the daemon rejects creation (bad container state, unsupported API, invalid options), the driver wraps the error. No exec session has started at this point.

Source

Thrown at drivers/docker/driver.go:1962

		return nil, fmt.Errorf("command is required but was empty")
	}

	createExecOpts := mclient.ExecCreateOptions{
		AttachStdin:  true,
		AttachStdout: true,
		AttachStderr: true,
		TTY:          opts.Tty,
		Cmd:          opts.Command,
	}

	client, err := d.getDockerClient()
	if err != nil {
		return nil, err
	}

	exec, err := client.ExecCreate(d.ctx, h.containerID, createExecOpts)
	if err != nil {
		return nil, fmt.Errorf("failed to create exec object: %v", err)
	}

	go func() {
		for {
			select {
			case <-ctx.Done():
				return
			case <-done:
				return
			case s, ok := <-opts.ResizeCh:
				if !ok {
					return
				}
				_, _ = client.ExecResize(d.ctx, exec.ID, mclient.ExecResizeOptions{
					Height: uint(s.Height),
					Width:  uint(s.Width),
				})
			}

View on GitHub (pinned to 482b49bf1a)

Solutions

  1. Verify the container is running: `docker ps | grep <containerID>`; re-run the task if it exited.
  2. Test manually: `docker exec <containerID> <command>` to reproduce outside Nomad.
  3. Check Docker client and daemon API version compatibility.
  4. Inspect dockerd logs (`journalctl -u docker`) for the underlying create-exec failure.

Example fix

// before
exec, err := client.ExecCreate(d.ctx, h.containerID, createExecOpts)
if err != nil {
    return nil, fmt.Errorf("failed to create exec object: %v", err)
}
// after
exec, err := client.ExecCreate(d.ctx, h.containerID, createExecOpts)
if err != nil {
    if errdefs.IsNotFound(err) {
        return nil, fmt.Errorf("container %q not running; cannot exec: %w", h.containerID, err)
    }
    return nil, fmt.Errorf("failed to create exec object: %v", err)
}
Defensive patterns

Strategy: try-catch

Validate before calling

// ensure container is running before exec
state, err := dockerClient.ContainerInspect(ctx, containerID, mclient.ContainerInspectOptions{})
if err != nil || !state.Container.State.Running { return errors.New("container not running") }

Type guard

func isExecCreateFailure(err error) bool { return strings.Contains(err.Error(), "failed to create exec object") }

Try / catch

out, err := driver.ExecTaskStreaming(ctx, taskID, opts)
if err != nil {
    if isExecCreateFailure(err) {
        // container likely stopped; verify and restart task before retrying
    }
    return err
}

Prevention

When it happens

Trigger: driver.ExecTaskStreaming proceeds past command validation but client.ExecCreate(ctx, h.containerID, createExecOpts) errors — container stopped/paused, exec unsupported in the container, or API version mismatch.

Common situations: Container already exited; `docker exec` disabled in the container's config; exec capability absent in minimal images (rare); dockerd restart mid-call; mismatched Docker client/daemon API versions.

Related errors


AI-assisted analysis of hashicorp/nomad@482b49bf1a (2026-09-04). Data as JSON: /api/errors/9a227e833d833b0f. Report an issue: GitHub.