task Block
Placement | job -> group -> task |
The task
block creates an individual unit of work, such as a Docker
container, web application, or batch processing.
task
Parameters
artifact
(Artifact: nil)
- Defines an artifact to download before running the task. This may be specified multiple times to download multiple artifacts.config
(map<string|string>: nil)
- Specifies the driver configuration, which is passed directly to the driver to start the task. The details of configurations are specific to each driver, so please see specific driver documentation for more information.constraint
(Constraint: nil)
- Specifies user-defined constraints on the task. This can be provided multiple times to define additional constraints.affinity
(Affinity: nil)
- This can be provided multiple times to define preferred placement criteria.dispatch_payload
(DispatchPayload: nil)
- Configures the task to have access to dispatch payloads.driver
- Specifies the task driver that should be used to run the task. See the driver documentation for what is available. Examples includedocker
,qemu
,java
andexec
.env
(Env: nil)
- Specifies environment variables that will be passed to the running process.identity
(Identity: nil)
- Expose Workload Identity to the task.kill_timeout
(string: "5s")
- Specifies the duration to wait for an application to gracefully quit before force-killing. Nomad first sends akill_signal
. If the task does not exit before the configured timeout,SIGKILL
is sent to the task. Note that the value set here is capped at the value set formax_kill_timeout
on the agent running the task, which has a default value of 30 seconds.kill_signal
(string)
- Specifies a configurable kill signal for a task, where the default is SIGINT (or SIGTERM fordocker
, or CTRL_BREAK_EVENT forraw_exec
on Windows). Note that this is only supported for drivers sending signals (currentlydocker
,exec
,raw_exec
, andjava
drivers).leader
(bool: false)
- Specifies whether the task is the leader task of the task group. If set totrue
, when the leader task completes, all other tasks within the task group will be gracefully shutdown. The shutdown process starts by applying theshutdown_delay
if configured. It then stops the the leader task first, followed by non-sidecar and non-poststop tasks, and finally sidecar tasks. Once this process completes, post-stop tasks are triggered. See the lifecycle documentation for a complete description of task lifecycle management.lifecycle
(Lifecycle: nil)
- Specifies when a task is run within the lifecycle of a task group. Added in Nomad v0.11.logs
(Logs: nil)
- Specifies logging configuration for thestdout
andstderr
of the task.meta
(Meta: nil)
- Specifies a key-value map that annotates with user-defined metadata.resources
(Resources: <required>)
- Specifies the minimum resource requirements such as RAM, CPU and devices.service
(Service: nil)
- Specifies integrations with Nomad or Consul for service discovery. Nomad automatically registers when a task is started and de-registers it when the task dies.shutdown_delay
(string: "0s")
- Specifies the duration to wait when killing a task between removing its service registrations from Consul or Nomad, and sending it a shutdown signal. Ideally services would fail health checks once they receive a shutdown signal. Alternatively,shutdown_delay
may be set to give in flight requests time to complete before shutting down. Thisshutdown_delay
only applies to services defined at the task level by theservice
block. In addition, task groups have their ownshutdown_delay
which waits between de-registering group services and stopping tasks.user
(string: <varies>)
- Specifies the user that will run the task. Defaults tonobody
for theexec
andjava
drivers. Docker and rkt images specify their own default users. This can only be set on Linux platforms, and clients can restrict which drivers are allowed to run tasks as certain users.template
(Template: nil)
- Specifies the set of templates to render for the task. Templates can be used to inject both static and dynamic configuration with data populated from environment variables, Consul and Vault.vault
(Vault: nil)
- Specifies the set of Vault policies required by the task. This overrides anyvault
block set at thegroup
orjob
level.volume_mount
(VolumeMount: nil)
- Specifies where a group volume should be mounted.kind
(string: <varies>)
- Used internally to manage tasks according to the value of this field. Initial use case is for Consul Connect.
task
Examples
The following examples only show the task
blocks. Remember that the
task
block is only valid in the placements listed above.
Docker Container
This example defines a task that starts a Docker container as a service. Docker is just one of many drivers supported by Nomad. Read more about drivers in the Nomad drivers documentation.
Metadata and Environment Variables
This example uses custom metadata and environment variables to pass information to the task.
Service Discovery
This example creates a service in Consul. To read more about service discovery in Nomad, please see the Nomad service discovery documentation.