這cron的沙盒模擬器給你一個想法:
Mins Hrs Day Mth DoW
*/10 * * * *
This run time (UTC) Sat 2016-Jan-23 0653
Forward Schedule Sat 2016-Jan-23 0700
Sat 2016-Jan-23 0710
Sat 2016-Jan-23 0720
它使用的語法:
每nth '0-23/n'
, '*/2
' 將每隔。
'*/1
'在別處通常是可以接受的,但在此標記爲可能是意外的條目。
例如見 「Run a cron job with Docker」(由Julien Boulay)
讓我們創建一個名爲「crontab
」新文件來描述我們的工作。
* * * * * root echo "Hello world" >> /var/log/cron.log 2>&1
# An empty line is required at the end of this file for a valid cron file.
下DockerFile描述了所有步驟來建立你的形象
FROM ubuntu:latest
MAINTAINER [email protected]
# Add crontab file in the cron directory
ADD crontab /etc/cron.d/hello-cron
# Give execution rights on the cron job
RUN chmod 0644 /etc/cron.d/hello-cron
# Create the log file to be able to run tail
RUN touch /var/log/cron.log
# Run the command on container startup
CMD cron && tail -f /var/log/cron.log
然後你就可以用
sudo docker build --rm -t ekito/cron-example .
打造形象
並運行它:
sudo docker run -t -i ekito/cron-example
要有耐心,等待2分鐘,您的命令行應顯示:
Hello world
Hello world
如果更換了第一個 '' 通過'/10',你將不得不等待下一個0或10或20或小時。
它將在0,10,20,...,50分鐘過後運行。 –