Running cron python jobs within docker

后端 未结 9 1416
挽巷
挽巷 2020-12-04 08:59

I would like to run a python cron job inside of a docker container in detached mode. My set-up is below:

My python script is test.py

#!/usr/bin/env pyt         


        
9条回答
  •  天命终不由人
    2020-12-04 09:46

    Adding crontab fragments in /etc/cron.d/ instead of using root's crontab might be preferable.

    This would:

    • Let you add additional cron jobs by adding them to that folder.
    • Save you a few layers.
    • Emulate how Debian distros do it for their own packages.

    Observe that the format of those files is a bit different from a crontab entry. Here's a sample from the Debian php package:

    # /etc/cron.d/php5: crontab fragment for php5
    #  This purges session files older than X, where X is defined in seconds
    #  as the largest value of session.gc_maxlifetime from all your php.ini
    #  files, or 24 minutes if not defined.  See /usr/lib/php5/maxlifetime
    
    # Look for and purge old sessions every 30 minutes
    09,39 *     * * *     root   [ -x /usr/lib/php5/maxlifetime ] && [ -x /usr/lib/php5/sessionclean ] && [ -d /var/lib/php5 ] && /usr/lib/php5/sessionclean /var/lib/php5 $(/usr/lib/php5/maxlifetime)
    

    Overall, from experience, running cron in a container does work very well (besides cron logging leaving a lot to be desired).

提交回复
热议问题