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:
Click the Services tab of the DC/OS web interface, then click RUN A SERVICE.
Click Single Container.
In the SERVICE ID field, enter a name for your service.
In the COMMAND field, enter
sleep 10
.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.
Click REVIEW & RUN and RUN SERVICE.
Figure 1. Create a service in the web interface
Click the name of your service in the Services view to see it running and monitor health.
Figure 2. Viewing a running service in the web interface
DC/OS CLI
Create and run a simple service from the DC/OS CLI:
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,
"portDefinitions": [
{
"protocol": "tcp",
"port": 10000
}
],
"requirePorts": false
}
Run the service with the following command.
dcos marathon app add my-app-cli.json
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.
Containerized service
DC/OS web interface
Create and run a containerized service from the DC/OS web interface:
Go to the
hello-dcos
page of the Mesosphere Docker Hub repository and note down the latest image tag.Click the Services tab of the DC/OS web interface, then click the RUN A SERVICE.
Click Single Container and enter a name for your service in the SERVICE ID field.
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.Figure 3. Containerized service in the web interface
Click REVIEW & RUN and RUN SERVICE.
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.
Figure 4. Viewing a containerized service in the web interface
DC/OS CLI
Create and run a containerized service from the CLI:
Go to the
hello-dcos
page of the Mesosphere Docker Hub repository and note down the latest image tag.Create a JSON file called
hello-dcos-cli.json
with the following contents. Replace<image-tag>
in thedocker:image
field with the tag you copied in step 1.{
"id": "/hello-dcos-cli",
"instances": 1,
"cpus": 1,
"mem": 128,
"container": {
"type": "DOCKER",
"docker": {
"image": "mesosphere/hello-dcos:<image-tag>",
"forcePullImage": false,
"privileged": false
}
},
"acceptedResourceRoles": ["slave_public"],
"portDefinitions": [
{
"protocol": "tcp",
"port": 10001
}
],
"requirePorts": false
}
Run the service with the following command.
dcos marathon app add hello-dcos-cli.json
Run the following command to verify that your service is running:
dcos marathon app list
In the Services tab of the DC/OS web interface, click the name of your service, then choose one of the task instances.
Click Logs, then toggle to the OUTPUT (STDOUT) view to see the output of the service.