Docker 容器使用 Ofelia 执行计划任务
Summary: Author: 张亚飞 | Read Time: 1 minute read | Published: 2020-02-16
Filed under
—
Categories:
MarkDown
—
Tags:
Tag,
Ofelia
笔记
GitHub: mcuadros/ofelia
专门为
Docker
环境设计的任务管理工具
Ofelia
一共支持4种类型的任务:
job-exec
: 在一个处于running
状态的容器运行job
[job-exec "job-executed-on-running-container"]
schedule = @hourly
container = my-container
command = touch /tmp/example
在处于 running
状态的 my-container
容器中,每隔一个小时运行一次 touch /tmp/example
命令.
job-run
: 指定一个镜像,用其创建一个新的容器,然后运行相应指令
[job-run "job-executed-on-new-container"]
schedule = @hourly
image = ubuntu:latest
command = touch /tmp/example
使用
ubuntu:latest
镜像构建运行的容器.
job-local
:在宿主机上运行
[job-local "job-executed-on-current-host"]
schedule = @hourly
command = touch /tmp/example
job-service-run
:在swarm
种运行
[job-service-run "service-executed-on-new-container"]
schedule = 0,20,40 * * * *
image = ubuntu
network = swarm_network
command = touch /tmp/example
启动服务
docker container run --rm --name=ofelia -v /var/run/docker.sock:/var/run/docker.sock:ro -v /home/core/data:/home/core/data mcuadros/ofelia:latest daemon --config=/home/core/data/ofelia/config.ini
/path/to/config.ini
[job-exec "job-executed-on-running-container"]
#schedule = @every 5s
schedule = */60 * * * *
no-overlap = true
container = php
#command = touch /tmp/example
#command = date
command = /usr/local/bin/php /www/Work/hs_api/artisan schedule:run
#[job-local "job-executed-on-current-host"]
#schedule = @every 1m
#schedule = */60 * * * *
#dir = /home/core/data/www/Work/hs_data
#command = /home/core/data/www/Work/hs_data/backup.sh
备用命令
docker run -it --rm --label ofelia.enabled=true --label ofelia.job-exec.test-exec-job.schedule="@every 5s" --label ofelia.job-exec.test-exec-job.command="uname -a" coam/cs.ss_proxy:0.0.2
docker run -it --rm -v /var/run/docker.sock:/var/run/docker.sock:ro --label ofelia.job-local.my-test-job.schedule="@every 5s" --label ofelia.job-local.my-test-job.command="date" mcuadros/ofelia:latest daemon --config=/path/to/config.ini
Comments