15. # There can only be a single job definition per file.
# Create a job with ID and Name 'example'
job "example" {
# Run the job in the global region, which is the default.
# region = "global"
# Specify the datacenters within the region this job can run in.
datacenters = ["dc1"]
# Service type jobs optimize for long-lived services. This is
# the default but we can change to batch for short-lived tasks.
# type = "service"
# Priority controls our access to resources and scheduling priority.
# This can be 1 to 100, inclusively, and defaults to 50.
# priority = 50
# Restrict our job to only linux. We can specify multiple
# constraints as needed.
constraint {
attribute = "$attr.kernel.name"
value = "linux"
}
# Configure the job to do rolling updates
update {
# Stagger updates every 10 seconds
stagger = "10s"
# Update a single task at a time
max_parallel = 1
}
# Create a 'cache' group. Each task in the group will be
# scheduled onto the same machine.
group "cache" {
# Control the number of instances of this groups.
# Defaults to 1
# count = 1
# Define a task to run
task "redis" {
# Use Docker to run the task.
driver = "docker"
# Configure Docker driver with the image
config {
image = "redis:latest"
}
# We must specify the resources required for
# this task to ensure it runs on a machine with
# enough capacity.
resources {
cpu = 500 # 500 Mhz
memory = 256 # 256MB
network {
mbits = 10
dynamic_ports = ["6379"]
}
}
}
}
}
zem@dev:~$ nomad init
Example job file written to example.nomad このような「.nomad」ファイルで
何を動かすか、リソースはどの
程度使うのか指定します。
16. zem@dev:~$ nomad run example.nomad
==> Monitoring evaluation "88fc77ac-d878-b27f-925c-c0e131658ac6"
Evaluation triggered by job "example"
Allocation "1170083d-dd2c-92ec-1e29-44f25eb3de75" created: node "2b4b3259-f143-2abf-46d4-629
05268263e", group "cache"
Evaluation status changed: "pending" -> "complete"
==> Evaluation "88fc77ac-d878-b27f-925c-c0e131658ac6" finished with status "complete"
2015/10/08 23:59:57 [DEBUG] driver.docker: docker pull redis:latest succeeded
2015/10/08 23:59:57 [DEBUG] driver.docker: using image 2f2578ff984f013c9a5d6cbb6fe061ed3f73…
2015/10/08 23:59:57 [INFO] driver.docker: identified image redis:latest as 2f2578ff984f013c…
2015/10/08 23:59:57 [DEBUG] driver.docker: using 268435456 bytes memory for redis:latest
2015/10/08 23:59:57 [DEBUG] driver.docker: using 500 cpu shares for redis:latest
2015/10/08 23:59:57 [WARN] driver.docker: no mode specified for networking, defaulting to bridge
2015/10/08 23:59:57 [DEBUG] driver.docker: using bridge as network mode
2015/10/08 23:59:57 [DEBUG] driver.docker: allocated port 128.199.223.107:44054 -> 6379 (mapped)
2015/10/08 23:59:57 [INFO] driver.docker: created container ca2c4efd37e4c5dee82da48fce248e…
2015/10/08 23:59:57 [INFO] driver.docker: started container ca2c4efd37e4c5dee82da48fce248e…
zem@dev:~$ docker ps
CONTAINER ID IMAGE COMMAND CREATED STATUS
PORTS NAMES
ca2c4efd37e4 redis:latest "/entrypoint.sh redis" 49 seconds ago Up 49
seconds 128.199.223.107:44054->6379/tcp desperate_mayer
あとは、「nomad」コマンドを通
して、nomadサーバが各々の手
法に従って、ジョブのスケジュー
リングを行います。ここでは、
Dockerコンテナのスケジューリン
グを行っています。dockerコマン
ドを使わずに、nomadを通して
Dockerコンテナを起動しました。