Product, Use Cases

The DCOS CLI: the command line tool for your datacenter

Sep 02, 2015

Tamar Ben-Shachar


4 min read

After you've created your DCOS Community Edition cluster and viewed the user interface, you'll very quickly want more fine-grained control over your datacenter. With the DCOS Command-Line Interface (CLI), you can easily install and manage datacenter services.
The CLI takes inspiration from the command-line tools we all know and love as developers. Easy to install, the CLI provides a local command, dcos, that makes it simple to execute common operations against your cluster.
The CLI supports Windows, Linux, and Unix-based platforms, including OS X. Comprehensive installation instructions are available in the Mesosphere documentation.
Just like your favourite flavor of Linux, DCOS makes it very easy to install applications from the DCOS package repository (also known as the Universe) with a single command.
Your can install your favourite distributed systems services such as HDFS and Cassandra with a single command. Simply type dcos package install your-favourite-service.
To see all available DCOS packages, simply run dcos package search.
This command uses our open-source repository (called "Universe") for installation. Be sure to run dcos package update to get the latest changes from this repo. If you don't see your favourite service, you should consider contributing to the Universe repo to add it!
When you install a package, the CLI tells you if a new subcommand is available. For example:
$ dcos package install helloworldA sample pre-installation messageContinue installing? [yes/no] yes Installing Marathon app for package [helloworld] version [0.1.0]Installing CLI subcommand for package [helloworld] version [0.1.0]New command available: dcos helloworldA sample post-installation message
The new subcommand provides utilities to interact with that new service. In an upcoming blog post we will describe how to create and add your own subcommand.
Deploying through Marathon
Mesos, the software that provides the ‘kernel' of the DCOS, is a cluster resource manager that provides an abstraction over numerous datacenter machines, providing a view of what looks like one large computer. With the DCOS CLI, you can deploy applications to your cluster of machines readily and easily.
An integral component of the DCOS is Marathon, an open-source, cluster-wide init system. Marathon allows you to run applications on your cluster (for example, a web server), taking care of the lifecycle of that application, restarting tasks if they fail, and allowing easy rolling upgrades of running applications.
DCOS and Marathon also support running Docker containers starting from the moment your DCOS cluster has been deployed, providing the most scalable way to run a containerized workload in your datacenter.
With the dcos marathon command, you can perform a wide array of tasks including adding an application, watching a deployment, and viewing the tasks for a given Marathon application.
For example, to add a simple Python webserver running inside a Docker container, you'd save the following JSON to a new file, definition.json:
{  "container": {    "type": "DOCKER",    "docker": {      "image": "superguenter/demo-app"    }  },  "cmd":  "python -m SimpleHTTPServer $PORT",  "id": "demo",  "cpus": 0.01,  "mem": 256,  "ports": [3000]}
Then simply run dcos marathon app add definition.json. Marathon then deploys and runs your application!
Keep your Datacenter Running
When running anything at scale, there are lots of things that can go wrong. Some of these can be anticipated, but occasionally failures will happen that require further diagnosis. DCOS makes life easier for the operator by automating the tracking of application instances that are launched on your cluster. To dig even deeper into application failures, the CLI gives you a handy way to view application logs, SSH into nodes, and to get detailed information about what's running.
Using the demo app that we added in the last section, we can use dcos task --json and dcos task --json --completed to get more information about our new app.
For a comprehensive description of the commands that we provide to ease debugging of your application, check out this post on the Mesosphere blog.
While command-line tools are useful for developers and operations personnel working to deploy or debug an application, they're also useful when automating parts of your infrastructure.
The CLI commands can output information about the state of your DCOS cluster in a tabular format, which you can use with all of your normal Linux/Unix tools like sed, grep and awk. You can also pass in the --json flag to get JSON output, which can then be easily filtered by using jq, a modern grep-like tool for JSON.
The example below shows all the marathon apps that have URIs:
dcos marathon app list --json | jq '.[] | select(.uris | length > 0) | .id
The CLI is open source and licensed under the Apache 2 license. If you'd like to contribute, please visit Github.
The DCOS CLI is now the main focus of development for Mesosphere; the previously-released Mesos CLI is no longer supported. The DCOS CLI has achieved (and surpassed) feature parity with the Mesos CLI. The Mesos CLI repository remains online on GitHub if you'd like to continue using it or would like to fork it.
The DCOS CLI also supports open-source Mesos and Marathon (instructions for this are in the README) but some commands that use functionality built into DCOS will not work.

Ready to get started?