Skip to content
Latchkey

nomad alloc exec: Run a Command in a Nomad Task

nomad alloc exec runs a command inside a running task, similar to docker exec, for debugging and one-off checks.

When a task is up but misbehaving, alloc exec drops you a shell or runs a single command inside it without touching the host.

What it does

nomad alloc exec executes a command in the namespace of a running tasks driver (for example inside the Docker container). It supports an interactive TTY for a shell or a single non-interactive command. -job resolves the latest allocation of a job so you do not need the alloc ID.

Common usage

Terminal
nomad alloc exec 8d5d <task> /bin/sh
# resolve the alloc from the job name
nomad alloc exec -job web /bin/sh
# run one command non-interactively
nomad alloc exec -task web 8d5d env

Options

FlagWhat it does
-task <name>Task to exec into when the alloc has several
-job <name>Use the latest allocation of a job by name
-iKeep stdin open (default true)
-tAllocate a pseudo-TTY (default true if a terminal)
-namespace <ns>Namespace of the allocation

In CI

In a non-interactive pipeline, pass -t=false so exec does not try to allocate a TTY and the command runs cleanly. exec into a task is the quickest way to confirm config or DNS inside the running environment during a deploy debug.

Common errors in CI

"Could not find task named: ..." means the wrong -task or an alloc with several tasks; name the task. "exec is not supported by driver ..." means the task driver does not support exec (some drivers do not). "Error: failed to exec into task: ... permission denied" means the token lacks alloc-exec on the namespace.

Related guides

Run this faster and cheaper on Latchkey managed runners. Start free →