github.com/diptanu/nomad@v0.5.7-0.20170516172507-d72e86cbe3d9/website/source/docs/operating-a-job/submitting-jobs.html.md (about) 1 --- 2 layout: "docs" 3 page_title: "Submitting Jobs - Operating a Job" 4 sidebar_current: "docs-operating-a-job-submitting-jobs" 5 description: |- 6 The job file is the unit of work in Nomad. Upon authoring, the job file is 7 submitted to the server for evaluation and scheduling. This section discusses 8 some techniques for submitting jobs. 9 --- 10 11 # Submitting Jobs 12 13 In Nomad, the description of the job and all its requirements are maintained in 14 a single file called the "job file". This job file resides locally on disk and 15 it is highly recommended that you check job files into source control. 16 17 The general flow for submitting a job in Nomad is: 18 19 1. Author a job file according to the job specification 20 1. Plan and review changes with a Nomad server 21 1. Submit the job file to a Nomad server 22 1. (Optional) Review job status and logs 23 24 Here is a very basic example to get you started. 25 26 ## Author a Job File 27 28 Authoring a job file is very easy. For more detailed information, please see the 29 [job specification](/docs/job-specification/index.html). Here is a sample job 30 file which runs a small docker container web server to get us started. 31 32 ```hcl 33 job "docs" { 34 datacenters = ["dc1"] 35 36 group "example" { 37 task "server" { 38 driver = "docker" 39 40 config { 41 image = "hashicorp/http-echo" 42 args = [ 43 "-listen", ":5678", 44 "-text", "hello world", 45 ] 46 } 47 48 resources { 49 network { 50 mbits = 10 51 port "http" { 52 static = "5678" 53 } 54 } 55 } 56 } 57 } 58 } 59 ``` 60 61 This job file exists on your local workstation in plain text. When you are 62 satisfied with this job file, you will plan and review the scheduler decision. 63 It is generally a best practice to commit job files to source control, 64 especially if you are working in a team. 65 66 ## Planning the Job 67 68 Once the job file is authored, we need to plan out the changes. The `nomad plan` 69 command invokes a dry-run of the scheduler and inform us of which scheduling 70 decisions would take place. 71 72 ```shell 73 $ nomad plan docs.nomad 74 ``` 75 76 The resulting output will look like: 77 78 ```text 79 + Job: "docs" 80 + Task Group: "example" (1 create) 81 + Task: "server" (forces create) 82 83 Scheduler dry-run: 84 - All tasks successfully allocated. 85 86 Job Modify Index: 0 87 To submit the job with version verification run: 88 89 nomad run -check-index 0 docs.nomad 90 91 When running the job with the check-index flag, the job will only be run if the 92 server side version matches the job modify index returned. If the index has 93 changed, another user has modified the job and the plan's results are 94 potentially invalid. 95 ``` 96 97 Note that no action was taken. This job is not running. This is a complete 98 dry-run and no allocations have taken place. 99 100 ## Submitting the Job 101 102 Assuming the output of the plan looks acceptable, we can ask Nomad to execute 103 this job. This is done via the `nomad run` command. We can optionally supply 104 the modify index provided to us by the plan command to ensure no changes to this 105 job have taken place between our plan and now. 106 107 ```shell 108 $ nomad run docs.nomad 109 ``` 110 111 The resulting output will look like: 112 113 ```text 114 ==> Monitoring evaluation "0d159869" 115 Evaluation triggered by job "docs" 116 Allocation "5cbf23a1" created: node "1e1aa1e0", group "example" 117 Evaluation status changed: "pending" -> "complete" 118 ==> Evaluation "0d159869" finished with status "complete" 119 ``` 120 121 Now that the job is scheduled, it may or may not be running. We need to inspect 122 the allocation status and logs to make sure the job started correctly. The next 123 section on [inspecting state](/docs/operating-a-job/inspecting-state.html) 124 details ways to examine this job's state. 125 126 ## Updating the Job 127 128 When making updates to the job, it is best to always run the plan command and 129 then the run command. For example: 130 131 ```diff 132 @@ -2,6 +2,8 @@ job "docs" { 133 datacenters = ["dc1"] 134 135 group "example" { 136 + count = "3" 137 + 138 task "server" { 139 driver = "docker" 140 ``` 141 142 After we save these changes to disk, run the plan command: 143 144 ```text 145 $ nomad plan docs.nomad 146 +/- Job: "docs" 147 +/- Task Group: "example" (2 create, 1 in-place update) 148 +/- Count: "1" => "3" (forces create) 149 Task: "server" 150 151 Scheduler dry-run: 152 - All tasks successfully allocated. 153 154 Job Modify Index: 131 155 To submit the job with version verification run: 156 157 nomad run -check-index 131 docs.nomad 158 159 When running the job with the check-index flag, the job will only be run if the 160 server side version matches the job modify index returned. If the index has 161 changed, another user has modified the job and the plan's results are 162 potentially invalid. 163 ``` 164 165 And then run the run command, assuming the output looks okay. Note that we are 166 including the "check-index" parameter. This will ensure that no remote changes 167 have taken place to the job between our plan and run phases. 168 169 ```text 170 nomad run -check-index 131 docs.nomad 171 ==> Monitoring evaluation "42d788a3" 172 Evaluation triggered by job "docs" 173 Allocation "04d9627d" created: node "a1f934c9", group "example" 174 Allocation "e7b8d4f5" created: node "012ea79b", group "example" 175 Allocation "5cbf23a1" modified: node "1e1aa1e0", group "example" 176 Evaluation status changed: "pending" -> "complete" 177 ==> Evaluation "42d788a3" finished with status "complete" 178 ``` 179 180 For more details on advanced job updating strategies such as canary builds and 181 build-green deployments, please see the documentation on [job update 182 strategies](/docs/operating-a-job/update-strategies/index.html).