【问题标题】:How to run a python cron application with docker? [duplicate]如何使用 docker 运行 python cron 应用程序? [复制]
【发布时间】:2019-11-05 22:24:16
【问题描述】:

我正在尝试在 docker 中使用 cron 运行我的两个 python 文件。 我有两个文件 a.py 和 b.py,它们将使用 cron 和它们之间的特定时间段运行。

如何通过 docker 解决这个问题?

【问题讨论】:

    标签: python docker cron


    【解决方案1】:

    这是我正在使用的。你可以参考

     FROM ubuntu:latest
    
    # Install cron
    RUN apt-get update
    RUN apt-get install cron
    RUN apt-get install -y python3
    RUN apt-get install -y python3-pip
    
    # Add crontab file in the cron directory
    ADD crontab /etc/cron.d/simple-cron
    
    # Add shell script and grant execution rights
    ADD dir/ /
    ADD requirements.txt /
    ADD script.sh /script.sh
    WORKDIR /
    RUN pip3 install -r requirements.txt
    RUN chmod +x /script.sh
    
    # Give execution rights on the cron job
    RUN chmod 0644 /etc/cron.d/simple-cron
    
    # Create the log file to be able to run tail
    RUN touch /var/log/cron.log
    
    # Run the command on container startup
    CMD printenv | sed 's/^\(.*\)$/export \1/g' > /env.sh && cron && tail -f /var/log/cron.log
    

    【讨论】:

    • 嗨!你能分享你的 simple-cron 文件吗?我也无法在我的 cron.log 文件中看到任何内容。你能帮我解决这个问题吗?
    猜你喜欢
    • 2017-02-16
    • 2014-04-18
    • 1970-01-01
    • 1970-01-01
    • 2021-01-12
    • 2017-05-29
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多