How to run a cron job inside a docker container?

前端 未结 20 1732
無奈伤痛
無奈伤痛 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:26

    I created a Docker image based on the other answers, which can be used like

    docker run -v "/path/to/cron:/etc/cron.d/crontab" gaafar/cron

    where /path/to/cron: absolute path to crontab file, or you can use it as a base in a Dockerfile:

    FROM gaafar/cron
    
    # COPY crontab file in the cron directory
    COPY crontab /etc/cron.d/crontab
    
    # Add your commands here
    

    For reference, the image is here.

提交回复
热议问题