Creating and Running a Service

Creating and Running a Service

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 Deploy Service.
  2. Enter a name for your service in the ID field. In the Command field, enter sleep 10.
  3. Click Deploy.

    Create a service in the DC/OS UI

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

    Running service in the DC/OS UI

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 Deploy Service.
  3. Enter a name for your service in the 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.

    Containerized service in the DC/OS UI

  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 Output (stdout) view to see the output of the service.

    Running containerized service in the DC/OS UI

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 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.