close
每個 Container Image 中一般只會做一件事,如一個 Apache Container 主要的功能是 Web 功能,你很難用以前的想法利用 Container 中的 CRON 排程其它定時的工作! 那要如何解決呢?
解決的方式也很簡單,就是使用一另一個 Container 去執行排程的工作! 而 Ofelia 即是這樣一個 Container
執行方式
pwd=`pwd`
docker run -d --restart always --name ofelia -v $pwd/data/ofelia:/etc/ofelia -v /etc/localtime:/etc/localtime:ro -v /var/run/docker.sock:/var/run/docker.sock mcuadros/ofelia:latest
設定檔
Ofelia 是使用 INI-style 的設定檔 config.ini
來設定要執行的工作, 該檔案放置於 /etc/ofelia 下面
檔案如下:
[global]
save-folder = /etc/ofelia
save-only-on-error = true
[job-exec "job-executed-on-running-container"] schedule = @hourly container = my-container command = touch /tmp/example [job-run "job-executed-on-new-container"] schedule = @hourly image = ubuntu:latest command = touch /tmp/example [job-local "job-executed-on-current-host"] schedule = @hourly command = touch /tmp/example [job-service-run "service-executed-on-new-container"] schedule = 0,20,40 * * * * image = ubuntu network = swarm_network command = touch /tmp/example
除錯
在 Global 的設定可設定是否儲存錯誤和錯誤檔案儲存的位置!
工作
分為以下四類
job-exec
: 在一個已執行中的 container 中執行工作.job-run
: 由 image 指定的 image 建立 container 後執行工作.job-local
: 在 ofelia container 內執行工作.job-service-run
: runs the command inside a new "run-once" service, for running inside a swarm
Schedule
預設了以下幾個
你也可手動設定,格式如下
schedule = 秒 分 時 日 月 星期幾
欄位 | 數值範圍 | |
秒 | 0 ~ 59 | |
分 | 0 ~ 59 | |
時 | 0 ~ 23 | |
日 | 1 ~ 31 | |
月 | 1 ~ 12 | |
星期幾 | 0 ~ 7 |
Sunday=0 or 7 sun,mon,tue,wed,thu,fri,sat |
每個欄為可以是以下表示
表示 | 意義 | 範例 |
一個數值 | 等於這個數值時執行 | 20 |
多個數值以逗點隔開 | 等於逗點隔開的數值時執行 | 20,40 |
兩個數值以-相連 | 在這兩個數值間都執行 | 20-40 |
星號 | 這個欄位為任何數值時都執行 | * |
星號除以一個數值 | 這個欄位可以被該數值整除時執行 | */5 |
文章標籤
全站熱搜