Files
nomad/website/source/docs/commands/alloc/exec.html.md.erb
2019-05-17 13:49:08 -04:00

84 lines
2.3 KiB
Plaintext

---
layout: "docs"
page_title: "Commands: alloc exec"
sidebar_current: "docs-commands-alloc-exec"
description: >
Stream the exec of a task.
---
# Command: alloc exec
**Alias: `nomad exec`**
The `alloc exec` command runs a command in a running allocation.
## Usage
```
nomad alloc exec [options] <allocation> <command> [<args>...]
```
The nomad exec command can be use to run commands inside a running task/allocation.
Use cases are for inspecting container state, debugging a failed application
without needing ssh access into the node that's running the allocation.
This command streams the execution of command in the given task in the allocation. If the
allocation is only running a single task, the task name can be omitted.
Optionally, the `-job` option may be used in which case a random allocation from
the given job will be chosen.
#
## General Options
<%= partial "docs/commands/_general_options" %>
## Exec Options
* `task`: Sets the task to exec command in. Defaults to first task.
* `-job`: Use a random allocation from the specified job ID.
* `-i`: Pass stdin to the container, defaults to true.
Pass `-i=false` to disable explicitly.
* `-t`: Allocate a pseudo-tty, defaults to true if stdin is detected to be a tty session.
Pass `-t=false` to disable explicitly.
* `-e` <escape_char>: Sets the escape character for sessions with a pty
(default: '~'). The escape character is only recognized at the beginning of a
line. The escape character followed by a dot ('.') closes the connection.
Setting the character to 'none' disables any escapes and makes the session fully
transparent.
## Examples
```
$ # interactive debugging
$ nomad alloc exec eb17e557 /bin/sh
/ # ps -ef
...
$ # run commands without starting an interactive session
$ nomad alloc exec eb17e557 cat /etc/resolv.conf
...
$ # run commands on an arbitrary alloc of a job
$ nomad alloc exec -job example printenv NOMAD_CPU_LIMIT
...
```
## Using Job ID instead of Allocation ID
Setting the `-job` flag causes a random allocation of the specified job to be
selected.
```
nomad alloc exec -job <job-id> <command> [<args>...]
```
Choosing a specific allocation is useful for debugging issues with a specific
instance of a service. For other operations using the `-job` flag may be more
convenient than looking up an allocation ID to use.