github.com/mattyr/nomad@v0.3.3-0.20160919021406-3485a065154a/website/source/docs/jobops/taskconfig.html.md (about)

     1  ---
     2  layout: "docs"
     3  page_title: "Operating a Job: Task Configuration"
     4  sidebar_current: "docs-jobops-task-config"
     5  description: |-
     6    Learn how to ship task configuration in a Nomad Job.
     7  ---
     8  
     9  # Task Configurations
    10  
    11  Most tasks need to be parameterized in some way. The simplest is via
    12  command-line arguments but often times tasks consume complex configurations via
    13  config files.  Here we explore how to configure Nomad jobs to support many
    14  common configuration use cases.
    15  
    16  ## Command-line Arguments
    17  
    18  The simplest type of configuration to support is tasks which take their
    19  configuration via command-line arguments that will not change.
    20  
    21  Nomad has many [drivers](/docs/drivers/index.html) and most support passing
    22  arguments to their tasks via the `args` parameter. To configure these simply
    23  provide the appropriate arguments. Below is an example using the [`docker`
    24  driver](/docs/drivers/docker.html) to launch `memcached(8)` and set its thread count
    25  to 4, increase log verbosity, as well as assign the correct port and address
    26  bindings using interpolation:
    27  
    28  ```
    29  task "memcached" {
    30      driver = "docker"
    31      
    32  	config {
    33  		image = "memcached:1.4.27"
    34  		args = [
    35  			# Set thread count
    36  			"-t", "4",
    37  
    38  			# Enable the highest verbosity logging mode
    39  			"-vvv", 
    40  
    41  			# Use interpolations to limit memory usage and bind
    42  			# to the proper address
    43  			"-m", "${NOMAD_MEMORY_LIMIT}",
    44  			"-p", "${NOMAD_PORT_db}",
    45  			"-l", "${NOMAD_ADDR_db}"
    46  		]
    47  
    48  		network_mode = "host"
    49  	}
    50  
    51  	resources {
    52  		cpu = 500 # 500 MHz
    53  		memory = 256 # 256MB
    54  		network {
    55  			mbits = 10
    56  			port "db" {
    57  			}
    58  		}
    59  	}
    60  }
    61  ```
    62  
    63  In the above example, we see how easy it is to pass configuration options using
    64  the `args` section and even see how
    65  [interpolation](docs/jobspec/interpreted.html) allows us to pass arguments
    66  based on the dynamic port and address Nomad chose for this task.
    67  
    68  ## Config Files
    69  
    70  Often times applications accept their configurations using configuration files
    71  or have so many arguments to be set it would be unwieldy to pass them via
    72  arguments. Nomad supports downloading
    73  [`artifacts`](/docs/jobspec/index.html#artifact_doc) prior to launching tasks.
    74  This allows shipping of configuration files and other assets that the task
    75  needs to run properly.
    76  
    77  An example can be seen below, where we download two artifacts, one being the
    78  binary to run and the other beings its configuration:
    79  
    80  ```
    81  task "example" {
    82      driver = "exec"
    83      
    84  	config {
    85  		command = "my-app"
    86  		args = ["-config", "local/config.cfg"]
    87  	}
    88  
    89      # Download the binary to run
    90  	artifact {
    91  		source = "http://example.com/example/my-app"
    92      }
    93  
    94  	# Download the config file
    95  	artifact {
    96  		source = "http://example.com/example/config.cfg"
    97      }
    98  }
    99  ```
   100  
   101  Here we can see a basic example of downloading static configuration files. By
   102  default, an `artifact` is downloaded to the task's `local/` directory but is
   103  [configurable](/docs/jobspec/index.html#artifact_doc).