github.com/maier/nomad@v0.4.1-0.20161110003312-a9e3d0b8549d/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 - `driver` - Specifies the task driver that should be used to run the 41 task. See the [driver documentation](/docs/drivers/index.html) for what 42 is available. Examples include `docker`, `qemu`, `java`, and `exec`. 43 44 - `env` <code>([Env][]: nil)</code> - Specifies environment variables that will 45 be passed to the running process. 46 47 - `kill_timeout` `(string: "5s")` - Specifies the duration to wait for an 48 application to gracefully quit before force-killing. Nomad sends an `SIGINT`. 49 If the task does not exit before the configured timeout, `SIGKILL` is sent to 50 the task. 51 52 - `logs` <code>([Logs][]: nil)</code> - Specifies logging configuration for the 53 `stdout` and `stderr` of the task. 54 55 - `meta` <code>([Meta][]: nil)</code> - Specifies a key-value map that annotates 56 with user-defined metadata. 57 58 - `resources` <code>([Resources][]: <required>)</code> - Specifies the minimum 59 resource requirements such as RAM, CPU, disk, and network. 60 61 - `service` <code>([Service][]: nil)</code> - Specifies integrations with 62 [Consul][] for service discovery. Nomad automatically registers when a task 63 is started and de-registers it when the task dies. 64 65 - `user` `(string: <varies>)` - Specifies the user that will run the task. This 66 defaults to the same user as the Nomad client. This can only be set on Linux 67 platforms. 68 69 - `vault` <code>([Vault][]: nil)</code> - Specifies the set of Vault policies 70 required by the task. This overrides any `vault` block set at the `group` or 71 `job` level. 72 73 ## `task` Examples 74 75 The following examples only show the `task` stanzas. Remember that the 76 `task` stanza is only valid in the placements listed above. 77 78 ### Docker Container 79 80 This example defines a task that starts a Docker container as a service. Docker 81 is just one of many drivers supported by Nomad. Read more about drivers in the 82 [Nomad drivers documentation](/docs/drivers/index.html). 83 84 ```hcl 85 task "server" { 86 driver = "docker" 87 config { 88 image = "hashicorp/http-echo" 89 args = ["-text", "hello world"] 90 } 91 92 resources { 93 network { 94 mbits = 250 95 } 96 } 97 } 98 ``` 99 100 ### Metadata and Environment Variables 101 102 This example uses custom metadata and environment variables to pass information 103 to the task. 104 105 ```hcl 106 task "server" { 107 driver = "exec" 108 config { 109 command = "/bin/env" 110 } 111 112 meta { 113 my-key = "my-value" 114 } 115 116 env { 117 MY_KEY = "${meta.my-key}" 118 } 119 120 resources { 121 cpu = 20 122 } 123 } 124 ``` 125 126 ### Service Discovery 127 128 This example creates a service in Consul. To read more about service discovery 129 in Nomad, please see the [Nomad service discovery documentation][service]. 130 131 ```hcl 132 task "server" { 133 driver = "docker" 134 config { 135 image = "hashicorp/http-echo" 136 args = ["-text", "hello world"] 137 } 138 139 service { 140 tags = ["default"] 141 142 check { 143 type = "tcp" 144 interval = "10s" 145 timeout = "2s" 146 } 147 } 148 149 resources { 150 cpu = 20 151 } 152 } 153 ``` 154 155 [artifact]: /docs/job-specification/artifact.html "Nomad artifact Job Specification" 156 [consul]: https://www.consul.io/ "Consul by HashiCorp" 157 [constraint]: /docs/job-specification/constraint.html "Nomad constraint Job Specification" 158 [env]: /docs/job-specification/env.html "Nomad env Job Specification" 159 [meta]: /docs/job-specification/meta.html "Nomad meta Job Specification" 160 [resources]: /docs/job-specification/resources.html "Nomad resources Job Specification" 161 [logs]: /docs/job-specification/logs.html "Nomad logs Job Specification" 162 [service]: /docs/service-discovery/index.html "Nomad Service Discovery"