Ken*_*ane 84
这是我如何运行我的一个cron容器.
Dockerfile:
FROM alpine:3.3
ADD crontab.txt /crontab.txt
ADD script.sh /script.sh
COPY entry.sh /entry.sh
RUN chmod 755 /script.sh /entry.sh
RUN /usr/bin/crontab /crontab.txt
CMD ["/entry.sh"]
Run Code Online (Sandbox Code Playgroud)
crontab.txt
*/30 * * * * /script.sh >> /var/log/script.log
Run Code Online (Sandbox Code Playgroud)
entry.sh
#!/bin/sh
# start cron
/usr/sbin/crond -f -l 8
Run Code Online (Sandbox Code Playgroud)
script.sh
#!/bin/sh
# code goes here.
echo "This is a script, run by cron!"
Run Code Online (Sandbox Code Playgroud)
像这样构建
docker build -t mycron .
Run Code Online (Sandbox Code Playgroud)
像这样跑
docker run -d mycron
Run Code Online (Sandbox Code Playgroud)
添加自己的脚本并编辑crontab.txt,然后构建映像并运行.由于它是基于高山,因此图像非常小.
TVK*_*TVK 16
谢谢你的模板.
我只想知道entry.sh中的一行
/usr/sbin/crond -f -L 8
crond -help产量:
Usage: crond -fbS -l N -d N -L LOGFILE -c DIR
-f Foreground
-b Background (default)
-S Log to syslog (default)
-l N Set log level. Most verbose:0, default:8
-d N Set log level, log to stderr
-L FILE Log to FILE
-c DIR Cron dir. Default:/var/spool/cron/crontabs
Run Code Online (Sandbox Code Playgroud)
所以也许你想宁愿把小l
/usr/sbin/crond -f -l 8
而不是大'L'
/usr/sbin/crond -f -L 8
将日志级别设置为默认值,因为指定的日志文件8似乎不是预期的.
Jar*_*zki 10
crond在 Alpine 上与tiny配合良好
RUN apk add --no-cache tini
ENTRYPOINT ["/sbin/tini", "--"]
CMD ["/usr/sbin/crond", "-f"]
Run Code Online (Sandbox Code Playgroud)
但不应作为容器主进程(PID 1)运行,因为僵尸收割问题和信号处理问题。有关详细信息,请参阅此 Docker PR和此博客文章。
Jes*_*sta 10
@ken-cochrane 的解决方案可能是最好的,但是,还有一种方法可以做到这一点,而无需创建额外的文件。
解决方法是在entrypoint.sh文件中设置 cron。
Dockerfile
...
# Your Dockerfile above
COPY entrypoint.sh /
RUN chmod +x /entrypoint.sh
ENTRYPOINT ["/entrypoint.sh"]
Run Code Online (Sandbox Code Playgroud)
入口点.sh
echo "* * * * * echo 'I love running my crons'" >> /etc/crontabs/root
crond -l 2 -f > /dev/stdout 2> /dev/stderr &
# You can put the rest of your entrypoint.sh below this line
...
Run Code Online (Sandbox Code Playgroud)
| 归档时间: |
|
| 查看次数: |
28770 次 |
| 最近记录: |