Skip to content

Instantly share code, notes, and snippets.

@vnext-nguyen-quyen
Last active January 9, 2023 07:40
Show Gist options
  • Select an option

  • Save vnext-nguyen-quyen/eb97f19381dec585522c253dc23399b0 to your computer and use it in GitHub Desktop.

Select an option

Save vnext-nguyen-quyen/eb97f19381dec585522c253dc23399b0 to your computer and use it in GitHub Desktop.

Revisions

  1. vnext-nguyen-quyen renamed this gist Jan 9, 2023. 1 changed file with 0 additions and 0 deletions.
    File renamed without changes.
  2. vnext-nguyen-quyen created this gist Jan 9, 2023.
    45 changes: 45 additions & 0 deletions gistfile1.txt
    Original file line number Diff line number Diff line change
    @@ -0,0 +1,45 @@
    1. Alpine (No need for redirection)

    using the default cron utility (busybox)

    ## Dockerfile
    =====
    FROM alpine:3.7

    # Setting up crontab
    COPY crontab /tmp/crontab
    RUN cat /tmp/crontab > /etc/crontabs/root


    CMD ["crond", "-f", "-l", "2"]
    =====

    ## Crontab
    =====
    * * * * * echo "Crontab is working - watchdog 1"
    =====

    2. Centos
    Redirection to /proc/1/fd/1 inside the crontab declaration line

    ## Dockerfile
    =====
    FROM centos:7

    RUN yum -y install crontabs

    ADD crontab /etc/cron.d/crontab
    RUN chmod 0644 /etc/cron.d/crontab
    RUN crontab /etc/cron.d/crontab


    CMD ["crond", "-n"]
    =====

    ## Crontab
    =====
    * * * * * echo "Crontab is working - watchdog 1" > /proc/1/fd/1
    =====


    => Test show cron ouput with docker logs {container_name}