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
- Verify the container is running: `docker ps | grep <containerID>`; re-run the task if it exited.
- Test manually: `docker exec <containerID> <command>` to reproduce outside Nomad.
- Check Docker client and daemon API version compatibility.
- 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
- Check container Running state before invoking exec.
- Keep Docker client/daemon API versions compatible.
- Watch for dockerd restarts; re-run tasks afterward.
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
- cmd is required, but was empty
- command is required but was empty
- failed to attach to exec: %v
- failed to inspect exec: %v
- command is not present
AI-assisted analysis of hashicorp/nomad@482b49bf1a (2026-09-04).
Data as JSON: /api/errors/9a227e833d833b0f.
Report an issue: GitHub.