Using dcos task exec

The dcos task exec command allows you to execute an arbitrary command inside of a task’s container and stream its output back to your local terminal to learn more about how a given task is behaving. It offers an experience very similar to docker exec, without any need for SSH keys.

To use the debugging feature, the service or job must be launched using either the Mesos container runtime or the Universal container runtime. Debugging cannot be used on containers launched with the Docker runtime. See Using Mesos Containerizers for more information.

dcos task exec --tty <task-id> <command>: streams STDOUT and STDERR from the remote terminal to your local terminal, but not as raw bytes. Instead, this option puts your local terminal into raw mode, allocates a remote pseudo terminal (PYT), and streams the STDOUT and STDERR through the remote PTY.

dcos task exec --interactive <task-id> <command> streams STDOUT and STDERR from the remote terminal to your local terminal and streams STDIN from your local terminal to the remote command.

dcos task exec --interactive --tty <task-id> <command>: streams STDOUT and STDERR from the remote terminal to your local terminal and streams STDIN from your local terminal to the remote terminal. Also puts your local terminal into raw mode; allocates a remote pseudo terminal (PYT); and streams STDOUT, STDERR, and STDIN through the remote PTY. This mode offers the maximum functionality.

Tips:

We have included the text of the full flags above for readability, but each one can be shortened. Instead of typing --interactive, you can just type -i. Likewise, instead of typing --tty, you can just type -t.

If your mode streams raw bytes, you won’t be able to launch programs like vim, because these programs require the use of control characters.

Quick start

Pipe output from a command running inside a container

You can run commands inside a container by using the dcos task exec command. In this example, a long running Marathon app is launched and then the dcos task exec command is used to get the hostname of the node running the app.

Create a Marathon app definition and name it my-app.json with the following contents:

Run this command to show the hostname of the container running your app, where <task-ID> is your task ID.

dcos task exec <task_id> hostname

The output should look similar to this:

ip-10-0-1-105.us-west-2.compute.internal

For more information about the dcos task exec command, see the CLI command reference.

Run an interactive command inside a task’s container

You can run interactive commands on machines in your cluster by using the dcos task exec command. In this example, the dcos task exec command is used to copy a simple script from your local machine to the task container on the node. The script is then administered locally by using the dcos task exec command.

Create a Marathon app definition and name it my-interactive-app.json with the following contents:

Tip: You can use shorthand abbreviations -i for --interactive or -t for --tty. Also, only the beginning unique characters of the <task_id> are required. For example, if your task ID is exec-test_20161214195 and there are no other task IDs that begin with the letter e, this is valid command syntax: dcos task exec -i -t e bash. For more information, see the CLI command reference.