docker 创建cron 定时任务

作者: 分类: linux 时间: 2025-08-08 评论: 暂无评论

DockerFile

FROM debian:latest

RUN apt-get update && apt-get install -y cron

COPY cronjobs /etc/cron.d/cronjobs
RUN chmod 0644 /etc/cron.d/cronjobs

RUN touch /var/log/cron.log

CMD cron && tail -f /var/log/cron.log

cronjobs

* * * * * root echo 'cron is running' >> /var/log/cron.log 2>&1
//创建镜像
docker build -t cron-app .