How to run a cron job inside a docker container?

前端 未结 20 1282
無奈伤痛
無奈伤痛 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.

    0 讨论(0)
  • 2020-11-22 06:28

    Here's my docker-compose based solution:

      cron:
        image: alpine:3.10
        command: crond -f -d 8
        depends_on:
          - servicename
        volumes:
          - './conf/cron:/etc/crontabs/root:z'
        restart: unless-stopped
    

    the lines with cron entries are on the ./conf/cron file.

    Note: this won't run commands that aren't on the alpine image.

    0 讨论(0)
提交回复
热议问题