docker python crontab 定时任务

背景:有10个一下定时任务,他们互补关联,需要放在server 上docker里面  run, 

目前任务少,还未安装airflow , 临时方案

使用:

1.下载镜像

sudo docker pull happysea/python:cronjob

2. 运行镜像

sudo docker run -itd --restart=always  --name  cronjob   happysea/python:cronjob

3.进入容器 

sudo docker exec -it   22421412421412  bash

4.拷贝python 脚本

scp  sea@127.0.0.2:/home/sea/python/xxx.py    /opt/python/

 编写脚本:略 

5.添加cron job

crontab -e
#添加你需要的脚本
0 2 * * * /home/sea/Desktop/baxiancode/start_daily_tops_service/start_daily_tops_service.sh
#*/30 * * * * nohup  /home/sea/Desktop/MyShop/shopmonitor/shopmonitor/shopmonitor/start_shop_monitor.sh >> /home/sea/Desktop/baxiancode/shopmonitor.log 2>&1 &

保存了crontab之后,我们还需要重启cron来应用这个计划任务。使用以下命令:

sudo service cron restart

crontab -l   命令列出它的全部信息

原文地址:https://www.cnblogs.com/lshan/p/15131911.html