我正在为一个守护进程运行一个docker。每隔几个小时,容器就会被杀死。我想添加一些钩子(回调),例如:
重启容器,然后在重新启动的容器上运行一些命令
使用Docker可以做到吗?
否则,有没有更好的方法来检测Python或Ruby的行为?
java invoked oom-killer: gfp_mask=0xd0, order=0, oom_score_adj=0
java cpuset=bcb33ac552c23cfa531814fbc3a64ae5cd8d85aa19245e1560e0ce3e3310c798 mems_allowed=0
CPU: 3 PID: 14182 Comm: java Not tainted 4.1.0-x86_64-linode59 #1
0000000000000000 ffff8800dc520800 ffffffff8195b396 ffff880002cf5ac0
ffffffff81955e58 ffff8800a2918c38 ffff8800f43c3e78 0000000000000000
ffff8800b5f687f0 000000000000000d ffffea0002d7da30 ffff88005bebdec0
Call Trace:
[<ffffffff8195b396>] ? dump_stack+0x40/0x50
[<ffffffff81955e58>] ? dump_header+0x7b/0x1fe
[<ffffffff8119655d>] ? __do_fault+0x3f/0x79
[<ffffffff811789d6>] ? find_lock_task_mm+0x2c/0x7b
[<ffffffff81961c55>] ? _raw_spin_unlock_irqrestore+0x2d/0x3e
[<ffffffff81178dee>] ? oom_kill_process+0xc5/0x387
[<ffffffff811789d6>] ? find_lock_task_mm+0x2c/0x7b
[<ffffffff811b76be>] ? mem_cgroup_oom_synchronize+0x3ad/0x4c7
[<ffffffff811b6c92>] ? mem_cgroup_is_descendant+0x29/0x29
[<ffffffff811796e7>] ? pagefault_out_of_memory+0x1c/0xc1
[<ffffffff81963e58>] ? page_fault+0x28/0x30
Task in /docker/bcb33ac552c23cfa531814fbc3a64ae5cd8d85aa19245e1560e0ce3e3310c798 killed as a result of limit of /docker/bcb33ac552c23cfa531814fbc3a64ae5cd8d85aa19245e1560e0ce3e3310c798
memory: usage 524288kB, limit 524288kB, failcnt 14716553
memory+swap: usage 0kB, limit 9007199254740988kB, failcnt 0
kmem: usage 0kB, limit 9007199254740988kB, failcnt 0
Memory cgroup stats for /docker/bcb33ac552c23cfa531814fbc3a64ae5cd8d85aa19245e1560e0ce3e3310c798: cache:72KB rss:524216KB rss_huge:0KB mapped_file:64KB writeback:0KB inactive_anon:262236KB active_anon:262044KB inactive_file:4KB active_file:4KB unevictable:0KB
[ pid ] uid tgid total_vm rss nr_ptes nr_pmds swapents oom_score_adj name
[14097] 1000 14097 5215 20 17 3 47 0 entry_point.sh
[14146] 0 14146 11960 0 30 3 101 0 sudo
[14150] 1000 14150 1112 7 8 3 22 0 xvfb-run
[14162] 1000 14162 51929 11220 90 3 95 0 Xvfb
[14169] 1000 14169 658641 18749 120 6 0 0 java
[14184] 1000 14184 28364 555 58 3 0 0 fluxbox
[24639] 1000 24639 5212 59 16 3 0 0 bash
Memory cgroup out of memory: Kill process 14169 (java) score 96 or sacrifice child
Killed process 14169 (java) total-vm:2634564kB, anon-rss:74996kB, file-rss:0kB
答案 0 :(得分:2)
Docker本身没有任何这样的机制。您所能做的就是传递<?xml version="1.0"?>
<form name="name" prefix=":mainForm:report:dynamic:">
<!--always add dynamic to jasper_cfg file-->
<menu id="serv_contr_out_id" label="Номер договора" required="true"/>
<menu id="work_order_out_id" label="Номер наряда-заказа" required="true"/>
<menu id="proj_number" label="Номер проекта" required="true"/>
<label id="improvement_notice_doc_id" label="Уведомление о несоответствии №"/>
<label id="improvement_notice_doc_created" label="Дата создания"/>
<menu id="improvement_notice_recipient" label="Кому" required="true"/>
<input_area id="improvement_notice_subject" label="Тема" required="true"/>
<menu id="improvement_notice_defect_equipment_id" required="true" label="Наименование изделия"/>
<upload id="improvement_notice_defect_equipment_attachment" required="true" label="Фотография изделия"/>
<date id="improvement_notice_start_date" required="true" label="Дата составления"/>
<date id="improvement_notice_end_date" required="true" label="Срок выполнения"/>
<date id="improvement_notice_issue_receive_date" required="true" label="Дата принятия предписание к исполнению"/>
<date id="improvement_notice_issue_issue_date" required="true" label="Дата выдачи предписания"/>
<label id="improvement_notice_issue_recipient" label="Представитель завода" required="true"/>
<menu id="improvement_notice_issue_is_notice_assigned" label="Подписано представителем завода?" required="true"/>
<label id="improvement_notice_employee_fio" label="Специалист ТН" required="true"/>
<upload id="improvement_notice_employee_signature" required="true" label="Подпись"/>
<menu id="improvement_notice_resolution_employee_fio" required="true" label="Специалист ТН, закрывший предписание"/>
<upload id="improvement_notice_resolution_employee_signature" required="true" label="Подпись специалиста ТН, закрывшего предписание"/>
<date id="improvement_notice_resolution_resolve_date" required="true" label="Дата закрытия предписания"/>
<upload id="improvement_notice_scan_document" anyFile="true" label="Сканированный документ"/>
<dynamic id="improvement_notice_defect_table" required="true" label="Выявленные нарушения">
<upload id="defect_equipment_attachment" label="Фотография нарушения"/>
<input_area id="defect_description" label="Описание" required="true"/>
<dynamic id="defect_std" required="true" label="Не соответствует">
<input id="defect_std_reference_paragraph" required="true" label="Параграфу(-ам)"/>
<menu id="defect_std_doc_name" required="true" label="Документу(-ам)"/>
</dynamic>
</dynamic>
<label id="improvement_notice_add_label" label="Добавить нарушение" required="true"/>
</form>
标志,告诉Docker什么时候应该尝试将失败的容器带回来。
但是,大多数想要保存容器的地方,你都会想要比--restart
标志更复杂的东西。一旦你使用runit或systemd来管理容器,就可以很容易地添加一些额外的shell代码来弄清楚最后一次调用崩溃的原因并根据它进行一些特殊的操作。