github.com/diptanu/nomad@v0.5.7-0.20170516172507-d72e86cbe3d9/website/source/docs/job-specification/task.html.md (about)

     1  ---
     2  layout: "docs"
     3  page_title: "task Stanza - Job Specification"
     4  sidebar_current: "docs-job-specification-task"
     5  description: |-
     6    The "task" stanza creates an individual unit of work, such as a Docker
     7    container, web application, or batch processing.
     8  ---
     9  
    10  # `task` Stanza
    11  
    12  The `task` stanza creates an individual unit of work, such as a Docker
    13  container, web application, or batch processing.
    14  
    15  ```hcl
    16  job "docs" {
    17    group "example" {
    18      task "server" {
    19        # ...
    20      }
    21    }
    22  }
    23  ```
    24  
    25  ## `task` Parameters
    26  
    27  - `artifact` <code>([Artifact][]: nil)</code> - Defines an artifact to download
    28    before running the task. This may be specified multiple times to download
    29    multiple artifacts.
    30  
    31  - `config` `(map<string|string>: nil)` - Specifies the driver configuration,
    32    which is passed directly to the driver to start the task. The details of
    33    configurations are specific to each driver, so please see specific driver
    34    documentation for more information.
    35  
    36  - `constraint` <code>([Constraint][]: nil)</code> - Specifies user-defined
    37    constraints on the task. This can be provided multiple times to define
    38    additional constraints.
    39  
    40  - `dispatch_payload` <code>([DispatchPayload][]: nil)</code> - Configures the
    41    task to have access to dispatch payloads.
    42  
    43  - `driver` - Specifies the task driver that should be used to run the
    44    task. See the [driver documentation](/docs/drivers/index.html) for what
    45    is available. Examples include `docker`, `qemu`, `java` and `exec`.
    46  
    47  - `env` <code>([Env][]: nil)</code> - Specifies environment variables that will
    48    be passed to the running process.
    49  
    50  - `kill_timeout` `(string: "5s")` - Specifies the duration to wait for an
    51    application to gracefully quit before force-killing. Nomad sends an `SIGINT`.
    52    If the task does not exit before the configured timeout, `SIGKILL` is sent to
    53    the task. Note that the value set here is capped at the value set for
    54    [`max_kill_timeout`][max_kill] on the agent running the task, which has a
    55    default value of 30 seconds.
    56  
    57  - `leader` `(bool: false)` - Specifies whether the task is the leader task of
    58    the task group. If set to true, when the leader task completes, all other
    59    tasks within the task group will be gracefully shutdown.
    60  
    61  - `logs` <code>([Logs][]: nil)</code> - Specifies logging configuration for the
    62    `stdout` and `stderr` of the task.
    63  
    64  - `meta` <code>([Meta][]: nil)</code> - Specifies a key-value map that annotates
    65    with user-defined metadata.
    66  
    67  - `resources` <code>([Resources][]: <required>)</code> - Specifies the minimum
    68    resource requirements such as RAM, CPU and network.
    69  
    70  - `service` <code>([Service][]: nil)</code> - Specifies integrations with
    71    [Consul][] for service discovery. Nomad automatically registers when a task
    72    is started and de-registers it when the task dies.
    73  
    74  - `user` `(string: <varies>)` - Specifies the user that will run the task.
    75    Defaults to `nobody` for the [`exec`][exec] and [`java`][java] drivers.
    76    [Docker][] and [rkt][] images specify their own default users.  This can only
    77    be set on Linux platforms, and clients can restrict
    78    [which drivers][user_drivers] are allowed to run tasks as
    79    [certain users][user_blacklist].
    80  
    81  - `template` <code>([Template][]: nil)</code> - Specifies the set of templates
    82    to render for the task. Templates can be used to inject both static and
    83    dynamic configuration with data populated from environment variables, Consul
    84    and Vault.
    85  
    86  - `vault` <code>([Vault][]: nil)</code> - Specifies the set of Vault policies
    87    required by the task. This overrides any `vault` block set at the `group` or
    88    `job` level.
    89  
    90  ## `task` Examples
    91  
    92  The following examples only show the `task` stanzas. Remember that the
    93  `task` stanza is only valid in the placements listed above.
    94  
    95  ### Docker Container
    96  
    97  This example defines a task that starts a Docker container as a service. Docker
    98  is just one of many drivers supported by Nomad. Read more about drivers in the
    99  [Nomad drivers documentation](/docs/drivers/index.html).
   100  
   101  ```hcl
   102  task "server" {
   103    driver = "docker"
   104    config {
   105      image = "hashicorp/http-echo"
   106      args  = ["-text", "hello world"]
   107    }
   108  
   109    resources {
   110      network {
   111        mbits = 250
   112      }
   113    }
   114  }
   115  ```
   116  
   117  ### Metadata and Environment Variables
   118  
   119  This example uses custom metadata and environment variables to pass information
   120  to the task.
   121  
   122  ```hcl
   123  task "server" {
   124    driver = "exec"
   125    config {
   126      command = "/bin/env"
   127    }
   128  
   129    meta {
   130      my-key = "my-value"
   131    }
   132  
   133    env {
   134      MY_KEY = "${meta.my-key}"
   135    }
   136  
   137    resources {
   138      cpu = 20
   139    }
   140  }
   141  ```
   142  
   143  ### Service Discovery
   144  
   145  This example creates a service in Consul. To read more about service discovery
   146  in Nomad, please see the [Nomad service discovery documentation][service].
   147  
   148  ```hcl
   149  task "server" {
   150    driver = "docker"
   151    config {
   152      image = "hashicorp/http-echo"
   153      args  = ["-text", "hello world"]
   154    }
   155  
   156    service {
   157      tags = ["default"]
   158  
   159      check {
   160        type     = "tcp"
   161        interval = "10s"
   162        timeout  = "2s"
   163      }
   164    }
   165  
   166    resources {
   167      cpu = 20
   168    }
   169  }
   170  ```
   171  
   172  [artifact]: /docs/job-specification/artifact.html "Nomad artifact Job Specification"
   173  [consul]: https://www.consul.io/ "Consul by HashiCorp"
   174  [constraint]: /docs/job-specification/constraint.html "Nomad constraint Job Specification"
   175  [dispatchpayload]: /docs/job-specification/dispatch_payload.html "Nomad dispatch_payload Job Specification"
   176  [env]: /docs/job-specification/env.html "Nomad env Job Specification"
   177  [meta]: /docs/job-specification/meta.html "Nomad meta Job Specification"
   178  [resources]: /docs/job-specification/resources.html "Nomad resources Job Specification"
   179  [logs]: /docs/job-specification/logs.html "Nomad logs Job Specification"
   180  [service]: /docs/service-discovery/index.html "Nomad Service Discovery"
   181  [exec]: /docs/drivers/exec.html "Nomad exec Driver"
   182  [java]: /docs/drivers/java.html "Nomad Java Driver"
   183  [Docker]: /docs/drivers/docker.html "Nomad Docker Driver"
   184  [rkt]: /docs/drivers/rkt.html "Nomad rkt Driver"
   185  [template]: /docs/job-specification/template.html "Nomad template Job Specification"
   186  [user_drivers]: /docs/agent/configuration/client.html#_quot_user_checked_drivers_quot_
   187  [user_blacklist]: /docs/agent/configuration/client.html#_quot_user_blacklist_quot_
   188  [max_kill]: /docs/agent/configuration/client.html#max_kill_timeout