Consult on nomad docker volumes
aaron0428 opened this issue · 9 comments
Hi:
Hello, I recently used the nomad to deploy the docker container cluster, encountered some problems, but would like to use the volumes function to mount the container path when the task can not run, the following is my json file content, can I ask if I can see Is not my json content format wrong:
{
"Job": {
"Region": "xiaoniu",
"ID": "example",
"ParentID": "",
"Name": "example-name",
"Type": "batch",
"Priority": 100,
"AllAtOnce": false,
"Datacenters": [
"rjds"
],
"TaskGroups": [
{
"Name": "example-task-group",
"Count": 1,
"Constraints": null,
"Tasks": [
{
"Name": "portal-merchant",
"Driver": "docker",
"Config": {
"network_mode":"host",
"image": "portal-xxxxxxxx_pre:1.0.2",
"auth": [{
"username":"xxxxxxx",
"password":"xxxxxxxxxxxx",
"server_address":"xxxxxxxxxxxxxxxxxxxx"
}],
"volumes":[{
"/data/docker/logs":"/usr/local/tomcat/logs",
"/data/docker/message":"/var/log/message"
}]
},
"Constraints":[
{
"LTarget": "${meta.svr_tpye}",
"RTarget": "ovirt",
"Operand": "="
}
],
"Env": {
"xiaoniu": "nnnn"
},
"Resources": {
"CPU": 1000,
"MemoryMB": 512,
"IOPS": 0,
"Networks": []
}
}
]
}
]
}
}
Here is the logs:
ID = example
Name = example-name
Type = batch
Priority = 100
Datacenters = rjds
Status = dead
Periodic = false
Parameterized = false
Summary
Task Group Queued Starting Running Failed Complete Lost
example-task-group 0 0 0 1 0 0
Allocations
ID Eval ID Node ID Task Group Desired Status Created At
62303df1 ed716882 d65365a5 example-task-group run failed 06/29/17 09:24:57 CST
Error reading file: Unexpected response code: 404 (task "portal-merchant" not started yet. No logs available)
Hey aaron0428 sorry to hear you are having issues, what version of nomad are you running the client against? I'll see if I can try to replicate the issue as well once I know.
Quick scan from the json file did notice a couple things:
- https://www.nomadproject.io/docs/drivers/docker.html#volume_driver is required to be declared when using volumes
- https://www.nomadproject.io/docs/drivers/docker.html#volumes, Volumes is a list type of strings:
["relative/to/task:/also/in/container"]
currently you have a list of an object:
"volumes": [
{
"/data/docker/logs": "/usr/local/tomcat/logs",
"/data/docker/message": "/var/log/message"
}
]
according to the documentation it should be:
"volumes": [
"/data/docker/logs:/usr/local/tomcat/logs",
"/data/docker/message:/var/log/message"
]
Please let me know if those change resolve the issue.
@jonathanrcross
"volumes": [
"/data/docker/logs:/usr/local/tomcat/logs",
"/data/docker/message:/var/log/message"
]
this change is can resolve the issue!!
thanks you very much!!!
@jonathanrcross
On Artifacts, I would like to ask me the following configuration is correct????
"Artifacts": [{
"source":"http://xx.xx.xx.xx/cobbler/pub/soft/monitor/telegraf-weiyi.sh",
"destination":"/tmp"
}],
Traceback (most recent call last):
File "run_job.py", line 40, in
test_register_job(nomad_setup)
File "run_job.py", line 17, in test_register_job
nomad_setup().job.register_job("example", jobs)
File "/usr/lib/python2.7/site-packages/nomad/api/job.py", line 140, in register_job
return self._post(id, json_dict=job)
File "/usr/lib/python2.7/site-packages/nomad/api/job.py", line 120, in _post
response = self._requester.post(url, json=kwargs["json_dict"], params=kwargs.get("params", None))
File "/usr/lib/python2.7/site-packages/nomad/api/base.py", line 57, in post
raise nomad.api.exceptions.BaseNomadException(response)
nomad.api.exceptions.BaseNomadException
Here is the json data::
{
"Job": {
"Region": "xiaoniu",
"ID": "example",
"ParentID": "",
"Name": "example-name",
"Type": "batch",
"Priority": 100,
"AllAtOnce": false,
"Datacenters": [
"rjds"
],
"TaskGroups": [
{
"Name": "example-task-group",
"Count": 1,
"Constraints": null,
"Tasks": [
{
"Name": "portal-merchant",
"Driver": "docker",
"Artifacts": [{
"source":"http://10.8.36.10/cobbler/pub/soft/monitor/telegraf-weiyi.sh",
"destination":"/tmp"
}],
"Config": {
"network_mode":"host",
"image": "xx.xx.xx.xx:5000/niudingfeng-pre/portal-merchant_pre:1.0.2",
"auth": [{
"username":"xxxxxx",
"password":"xxxxxxxxx",
"server_address":"xxxxxxxxxxxxxx"
}],
"volumes":[
"/data/docker/logs:/usr/local/tomcat/logs",
"/data/docker/message:/var/log"
]
},
"Constraints":[
{
"LTarget": "${meta.svr_tpye}",
"RTarget": "ovirt",
"Operand": "="
}
],
"Env": {
"xiaoniu": "nnnn"
},
"Resources": {
"CPU": 1000,
"MemoryMB": 512,
"IOPS": 0,
"Networks": []
}
}
]
}
]
}
}
@aaron0428, https://www.nomadproject.io/docs/job-specification/artifact.html, is an object type. So it should be:
"Artifacts":
{
"source": "http://10.8.36.10/cobbler/pub/soft/monitor/telegraf-weiyi.sh",
"destination": "/tmp"
},
python-nomad is only passing the the json to the nomad run uri. Anything that is valid when running nomad validate <job>.nomad
should work and you can convert that nomad job to json using nomad run -output <job>.nomad
. Hope this helps.
@jonathanrcross
Thank you!
The problem has been solved!