github.com/hspak/nomad@v0.7.2-0.20180309000617-bc4ae22a39a5/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 - `kill_signal` `(string)` - Specifies a configurable kill signal for a task, 58 where the default is SIGINT. Note that this is only supported for drivers 59 sending signals (currently `docker`, `exec`, `raw_exec`, and `java` drivers). 60 61 - `leader` `(bool: false)` - Specifies whether the task is the leader task of 62 the task group. If set to true, when the leader task completes, all other 63 tasks within the task group will be gracefully shutdown. 64 65 - `logs` <code>([Logs][]: nil)</code> - Specifies logging configuration for the 66 `stdout` and `stderr` of the task. 67 68 - `meta` <code>([Meta][]: nil)</code> - Specifies a key-value map that annotates 69 with user-defined metadata. 70 71 - `resources` <code>([Resources][]: <required>)</code> - Specifies the minimum 72 resource requirements such as RAM, CPU and network. 73 74 - `service` <code>([Service][]: nil)</code> - Specifies integrations with 75 [Consul][] for service discovery. Nomad automatically registers when a task 76 is started and de-registers it when the task dies. 77 78 - `shutdown_delay` `(string: "0s")` - Specifies the duration to wait when 79 killing a task between removing it from Consul and sending it a shutdown 80 signal. Ideally services would fail healthchecks once they receive a shutdown 81 signal. Alternatively `shutdown_delay` may be set to give in flight requests 82 time to complete before shutting down. 83 84 - `user` `(string: <varies>)` - Specifies the user that will run the task. 85 Defaults to `nobody` for the [`exec`][exec] and [`java`][java] drivers. 86 [Docker][] and [rkt][] images specify their own default users. This can only 87 be set on Linux platforms, and clients can restrict 88 [which drivers][user_drivers] are allowed to run tasks as 89 [certain users][user_blacklist]. 90 91 - `template` <code>([Template][]: nil)</code> - Specifies the set of templates 92 to render for the task. Templates can be used to inject both static and 93 dynamic configuration with data populated from environment variables, Consul 94 and Vault. 95 96 - `vault` <code>([Vault][]: nil)</code> - Specifies the set of Vault policies 97 required by the task. This overrides any `vault` block set at the `group` or 98 `job` level. 99 100 ## `task` Examples 101 102 The following examples only show the `task` stanzas. Remember that the 103 `task` stanza is only valid in the placements listed above. 104 105 ### Docker Container 106 107 This example defines a task that starts a Docker container as a service. Docker 108 is just one of many drivers supported by Nomad. Read more about drivers in the 109 [Nomad drivers documentation](/docs/drivers/index.html). 110 111 ```hcl 112 task "server" { 113 driver = "docker" 114 config { 115 image = "hashicorp/http-echo" 116 args = ["-text", "hello world"] 117 } 118 119 resources { 120 network { 121 mbits = 250 122 } 123 } 124 } 125 ``` 126 127 ### Metadata and Environment Variables 128 129 This example uses custom metadata and environment variables to pass information 130 to the task. 131 132 ```hcl 133 task "server" { 134 driver = "exec" 135 config { 136 command = "/bin/env" 137 } 138 139 meta { 140 my-key = "my-value" 141 } 142 143 env { 144 MY_KEY = "${meta.my-key}" 145 } 146 147 resources { 148 cpu = 20 149 } 150 } 151 ``` 152 153 ### Service Discovery 154 155 This example creates a service in Consul. To read more about service discovery 156 in Nomad, please see the [Nomad service discovery documentation][service]. 157 158 ```hcl 159 task "server" { 160 driver = "docker" 161 config { 162 image = "hashicorp/http-echo" 163 args = ["-text", "hello world"] 164 } 165 166 service { 167 tags = ["default"] 168 169 check { 170 type = "tcp" 171 interval = "10s" 172 timeout = "2s" 173 } 174 } 175 176 resources { 177 cpu = 20 178 } 179 } 180 ``` 181 182 [artifact]: /docs/job-specification/artifact.html "Nomad artifact Job Specification" 183 [consul]: https://www.consul.io/ "Consul by HashiCorp" 184 [constraint]: /docs/job-specification/constraint.html "Nomad constraint Job Specification" 185 [dispatchpayload]: /docs/job-specification/dispatch_payload.html "Nomad dispatch_payload Job Specification" 186 [env]: /docs/job-specification/env.html "Nomad env Job Specification" 187 [meta]: /docs/job-specification/meta.html "Nomad meta Job Specification" 188 [resources]: /docs/job-specification/resources.html "Nomad resources Job Specification" 189 [logs]: /docs/job-specification/logs.html "Nomad logs Job Specification" 190 [service]: /docs/service-discovery/index.html "Nomad Service Discovery" 191 [exec]: /docs/drivers/exec.html "Nomad exec Driver" 192 [java]: /docs/drivers/java.html "Nomad Java Driver" 193 [Docker]: /docs/drivers/docker.html "Nomad Docker Driver" 194 [rkt]: /docs/drivers/rkt.html "Nomad rkt Driver" 195 [template]: /docs/job-specification/template.html "Nomad template Job Specification" 196 [user_drivers]: /docs/agent/configuration/client.html#_quot_user_checked_drivers_quot_ 197 [user_blacklist]: /docs/agent/configuration/client.html#_quot_user_blacklist_quot_ 198 [max_kill]: /docs/agent/configuration/client.html#max_kill_timeout