Tutorial - Creating and Running a Service

Creating and deploying a service and a containerized service

IMPORTANT: Tutorials are intended to give you hands-on experience working with a limited set of DC/OS features with no implied or explicit warranty of any kind. None of the information provided—including sample scripts, commands, or applications—is officially supported by Mesosphere. You should not use this information in a production environment without independent testing and validation.

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

One-command service

DC/OS web interface

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 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.
      • UNIVERSAL CONTAINER RUNTIME (UCR) Universal Container Runtime (UCR) using native Mesos engine. Supports Docker file format, multiple containers (pods), and GPU resources. If you select this option, you can optionally specify a Docker container image in the CONTAINER IMAGE field.

      For more information, see Using Containerizers.

  3. Click REVIEW & RUN and RUN SERVICE.

    Create a service in the DC/OS UI

    Figure 1. Create a service in the web interface

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

    Running service in the DC/OS UI

    Figure 2. Viewing a running service in the web interface

DC/OS CLI

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:

    1. {
    2. "id": "/my-app-cli",
    3. "cmd": "sleep 10",
    4. "instances": 1,
    5. "cpus": 1,
    6. "mem": 128,
    7. "portDefinitions": [
    8. {
    9. "protocol": "tcp",
    10. "port": 10000
    11. }
    12. ],
    13. "requirePorts": false
    14. }
  2. Run the service with the following command.

    1. dcos marathon app add my-app-cli.json
  3. Run the following command to verify that your service is running:

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

Containerized service

DC/OS web interface

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.

    Containerized service in the DC/OS UI

    Figure 3. Containerized service in the web interface

  5. Click REVIEW & RUN and RUN SERVICE.

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

    Running containerized service in the DC/OS UI

    Figure 4. Viewing a containerized service in the web interface

DC/OS CLI

Create and run a containerized service from the 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.

    1. {
    2. "id": "/hello-dcos-cli",
    3. "instances": 1,
    4. "cpus": 1,
    5. "mem": 128,
    6. "container": {
    7. "type": "DOCKER",
    8. "docker": {
    9. "image": "mesosphere/hello-dcos:<image-tag>",
    10. "forcePullImage": false,
    11. "privileged": false
    12. }
    13. },
    14. "acceptedResourceRoles": ["slave_public"],
    15. "portDefinitions": [
    16. {
    17. "protocol": "tcp",
    18. "port": 10001
    19. }
    20. ],
    21. "requirePorts": false
    22. }
  3. Run the service with the following command.

    1. dcos marathon app add hello-dcos-cli.json
  4. Run the following command to verify that your service is running:

    1. dcos marathon app list
  5. In the Services tab of the DC/OS web interface, click the name of your service, then choose one of the task instances.

  6. Click Logs, then toggle to the OUTPUT (STDOUT) view to see the output of the service.