How to run a cron job inside a docker container?

前端 未结 20 1578
無奈伤痛
無奈伤痛 2020-11-22 05:36

I am trying to run a cronjob inside a docker container that invokes a shell script.

Yesterday I have been searching all over the web and stack overflow, but I could

20条回答
  •  一整个雨季
    2020-11-22 06:22

    For those who wants to use a simple and lightweight image:

    FROM alpine:3.6
    
    # copy crontabs for root user
    COPY config/cronjobs /etc/crontabs/root
    
    # start crond with log level 8 in foreground, output to stderr
    CMD ["crond", "-f", "-d", "8"]
    

    Where cronjobs is the file that contains your cronjobs, in this form:

    * * * * * echo "hello stackoverflow" >> /test_file 2>&1
    # remember to end this file with an empty new line
    

提交回复
热议问题