github.com/diptanu/nomad@v0.5.7-0.20170516172507-d72e86cbe3d9/website/source/docs/operating-a-job/configuring-tasks.html.md (about) 1 --- 2 layout: "docs" 3 page_title: "Configuring Tasks - Operating a Job" 4 sidebar_current: "docs-operating-a-job-configuring-tasks" 5 description: |- 6 Most applications require some kind of configuration. Whether this 7 configuration is provided via the command line or via a configuration file, 8 Nomad has built-in functionality for configuration. This section details two 9 common patterns for configuring tasks. 10 --- 11 12 # Configuring Tasks 13 14 Most applications require some kind of configuration. The simplest way is via 15 command-line arguments, but often times tasks consume complex configurations via 16 config files. This section explores how to configure Nomad jobs to support many 17 common configuration use cases. 18 19 ## Command-line Arguments 20 21 Many tasks accept configuration via command-line arguments that do not change 22 over time. 23 24 For example, consider the [http-echo](https://github.com/hashicorp/http-echo) 25 server which is a small go binary that renders the provided text as a webpage. The binary accepts two parameters: 26 27 * `-listen` - the address:port to listen on 28 * `-text` - the text to render as the HTML page 29 30 Outside of Nomad, the server is started like this: 31 32 ```shell 33 $ http-echo -listen=":5678" -text="hello world" 34 ``` 35 36 The Nomad equivalent job file might look something like this: 37 38 ```hcl 39 job "docs" { 40 datacenters = ["dc1"] 41 42 group "example" { 43 task "server" { 44 driver = "exec" 45 46 config { 47 command = "/bin/http-echo" 48 args = [ 49 "-listen", ":5678", 50 "-text", "hello world", 51 ] 52 } 53 54 resources { 55 network { 56 mbits = 10 57 port "http" { 58 static = "5678" 59 } 60 } 61 } 62 } 63 } 64 } 65 ``` 66 67 ~> **This assumes** the <tt>http-echo</tt> binary is already installed and available in the system path. Nomad can also optionally fetch the binary using the <tt>artifact</tt> resource. 68 69 Nomad has many [drivers](/docs/drivers/index.html), and most support passing 70 arguments to their tasks via the `args` parameter. This option also optionally 71 accepts [Nomad interpolation](/docs/runtime/interpolation.html). For example, if 72 you wanted Nomad to dynamically allocate a high port to bind the service on 73 instead of relying on a static port for the previous job: 74 75 ```hcl 76 job "docs" { 77 datacenters = ["dc1"] 78 79 group "example" { 80 task "server" { 81 driver = "exec" 82 83 config { 84 command = "/bin/http-echo" 85 args = [ 86 "-listen", ":${NOMAD_PORT_http}", 87 "-text", "hello world", 88 ] 89 } 90 91 resources { 92 network { 93 mbits = 10 94 port "http" {} 95 } 96 } 97 } 98 } 99 } 100 ``` 101 102 ## Configuration Files 103 104 Not all applications accept their configuration via command-line flags. 105 Sometimes applications accept their configurations using files instead. Nomad 106 supports downloading [artifacts](/docs/job-specification/artifact.html) prior to 107 launching tasks. This allows shipping of configuration files and other assets 108 that the task needs to run properly. 109 110 Here is an example job which pulls down a configuration file as an artifact: 111 112 ```hcl 113 job "docs" { 114 datacenters = ["dc1"] 115 116 group "example" { 117 task "server" { 118 driver = "exec" 119 120 artifact { 121 source = "http://example.com/config.hcl" 122 destination = "local/config.hcl" 123 } 124 125 config { 126 command = "my-app" 127 args = [ 128 "-config", "local/config.hcl", 129 ] 130 } 131 } 132 } 133 } 134 ``` 135 136 For more information on the artifact resource, please see the [artifact documentation](/docs/job-specification/artifact.html).