}}

Creating and Running a Service

Updated: July 17, 2017

This tutorial shows how to create and deploy a simple one-command service and a containerized service using both the DC/OS web interface and the CLI.

Prerequisites

Create and Run a Simple Service from the DC/OS Web Interface

  1. Click the Services tab of the DC/OS web interface, then click the RUN A SERVICE.
  2. Click Single Container.
    1. In the SERVICE ID field, enter a name for your service.
    2. In the Command field, enter sleep 10.
    3. Click MORE SETTINGS and choose your container runtime.
    • DOCKER ENGINE Use this option if you require specific features of the Docker package. If you select this option, you must specify a Docker container image in the Container Image field. For example, you can specify the Alpine Docker image.
    • MESOS RUNTIME Use this option if you prefer the original Mesos container runtime. It does not support Docker containers.
    • UNIVERSAL CONTAINER RUNTIME Use this option if you are using Pods or GPUs. This option also supports Docker images without depending on the Docker Engine. If you select this option, you can optionally specify a Docker container image in the Container Image field. For example, you can specify the Alpine Docker image.

      For more information, see the containerizer documentation.

  3. Click REVIEW & RUN.

  4. That’s it! Click the name of your service in the Services view to see it running and monitor health.

Create and Run a Simple Service from the DC/OS CLI

  1. Create a JSON file called my-app-cli.json with the following contents:

    {
      "id": "/my-app-cli",
      "cmd": "sleep 10",
      "instances": 1,
      "cpus": 1,
      "mem": 128,
      "disk": 0,
      "gpus": 0,
      "backoffSeconds": 1,
      "backoffFactor": 1.15,
      "maxLaunchDelaySeconds": 3600,
      "upgradeStrategy": {
        "minimumHealthCapacity": 1,
        "maximumOverCapacity": 1
      },
      "portDefinitions": [
        {
          "protocol": "tcp",
          "port": 10000
        }
      ],
      "requirePorts": false
    }
    
  2. Run the service with the following command.
    dcos marathon app add my-app-cli.json
    
  3. Run the following command to verify that your service is running:
    dcos marathon app list
    

    You can also click the name of your service in the Services view of the DC/OS web interface to see it running and monitor health.

Create and Run a Containerized Service from the DC/OS Web Interface

  1. Go to the hello-dcos page of the Mesosphere Docker Hub repository and note down the latest image tag.
  2. Click the Services tab of the DC/OS web interface, then click the RUN A SERVICE.
  3. Click Single Container and enter a name for your service in the SERVICE ID field.
  4. Click the Container Settings tab and enter the following in the Container Image field: mesosphere/hello-dcos:<image-tag>. Replace <image-tag> with the tag you copied in step 1.

  5. Click Deploy.

  6. In the Services tab, click the name of your service, then choose on of the task instances. Click Logs, then toggle to the STDERR and STDOUT to see the output of the service.

Create and Run a Containerized Service from the DC/OS CLI

  1. Go to the hello-dcos page of the Mesosphere Docker Hub repository and note down the latest image tag.
  2. Create a JSON file called hello-dcos-cli.json with the following contents. Replace <image-tag> in the docker:image field with the tag you copied in step 1.

    {
      "id": "/hello-dcos-cli",
      "instances": 1,
      "cpus": 1,
      "mem": 128,
      "disk": 0,
      "gpus": 0,
      "backoffSeconds": 1,
      "backoffFactor": 1.15,
      "maxLaunchDelaySeconds": 3600,
      "container": {
        "docker": {
          "image": "mesosphere/hello-dcos:<image-tag>",
          "forcePullImage": false,
          "privileged": false,
          "network": "HOST"
        }
      },
      "upgradeStrategy": {
        "minimumHealthCapacity": 1,
        "maximumOverCapacity": 1
      },
      "portDefinitions": [
        {
          "protocol": "tcp",
          "port": 10001
        }
      ],
      "requirePorts": false
    }
    
  3. Run the service with the following command.
    dcos marathon app add hello-dcos-cli.json
    
  4. Run the following command to verify that your service is running:
    dcos marathon app list
    
  5. In the Services tab of the DC/OS web interface, click the name of your service, then choose on of the task instances. Click Logs, then toggle to the Output (stdout) view to see the output of the service.