2019-05-13 00:03:31 +00:00
|
|
|
---
|
|
|
|
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>...]
|
2019-05-17 17:39:09 +00:00
|
|
|
```
|
|
|
|
|
2019-05-13 00:03:31 +00:00
|
|
|
|
2019-05-17 17:39:09 +00:00
|
|
|
The nomad exec command can be use to run commands inside a running task/allocation.
|
2019-05-13 00:03:31 +00:00
|
|
|
|
2019-05-17 17:39:09 +00:00
|
|
|
Use cases are for inspecting container state, debugging a failed application
|
|
|
|
without needing ssh access into the node that's running the allocation.
|
2019-05-13 00:03:31 +00:00
|
|
|
|
2019-05-17 17:39:09 +00:00
|
|
|
This command streams the execution of command in the given task in the allocation. If the
|
2019-05-13 00:03:31 +00:00
|
|
|
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
|
|
|
|
|
2019-05-17 17:39:09 +00:00
|
|
|
* `task`: Sets the task to exec command in. Defaults to first task.
|
2019-05-13 00:03:31 +00:00
|
|
|
|
|
|
|
* `-job`: Use a random allocation from the specified job ID.
|
|
|
|
|
2019-05-17 17:39:09 +00:00
|
|
|
* `-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.
|
2019-05-13 00:03:31 +00:00
|
|
|
|
2019-05-17 17:39:09 +00:00
|
|
|
* `-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.
|
2019-05-13 00:03:31 +00:00
|
|
|
|
|
|
|
|
|
|
|
## Examples
|
|
|
|
|
|
|
|
```
|
2019-05-17 17:39:09 +00:00
|
|
|
$ # interactive debugging
|
2019-05-13 00:03:31 +00:00
|
|
|
$ nomad alloc exec eb17e557 /bin/sh
|
2019-05-17 17:39:09 +00:00
|
|
|
/ # ps -ef
|
|
|
|
...
|
2019-05-13 00:03:31 +00:00
|
|
|
|
2019-05-17 17:39:09 +00:00
|
|
|
$ # run commands without starting an interactive session
|
|
|
|
$ nomad alloc exec eb17e557 cat /etc/resolv.conf
|
|
|
|
...
|
2019-05-13 00:03:31 +00:00
|
|
|
|
2019-05-17 17:39:09 +00:00
|
|
|
$ # run commands on an arbitrary alloc of a job
|
|
|
|
$ nomad alloc exec -job example printenv NOMAD_CPU_LIMIT
|
|
|
|
...
|
2019-05-13 00:03:31 +00:00
|
|
|
```
|
|
|
|
|
|
|
|
## 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>...]
|
|
|
|
```
|
|
|
|
|
|
|
|
|
2019-05-17 17:39:09 +00:00
|
|
|
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.
|