How to run a cron job inside a docker container?

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

    When running on some trimmed down images that restrict root access, I had to add my user to the sudoers and run as sudo cron

    FROM node:8.6.0
    RUN apt-get update && apt-get install -y cron sudo
    
    COPY crontab /etc/cron.d/my-cron
    RUN chmod 0644 /etc/cron.d/my-cron
    RUN touch /var/log/cron.log
    
    # Allow node user to start cron daemon with sudo
    RUN echo 'node ALL=NOPASSWD: /usr/sbin/cron' >>/etc/sudoers
    
    ENTRYPOINT sudo cron && tail -f /var/log/cron.log

    Maybe that helps someone

提交回复
热议问题