Skip to content

Instantly share code, notes, and snippets.

@hyunjun
Last active December 22, 2019 15:41
Show Gist options
  • Save hyunjun/56159df74cbf3aafc936c3b199e99891 to your computer and use it in GitHub Desktop.
Save hyunjun/56159df74cbf3aafc936c3b199e99891 to your computer and use it in GitHub Desktop.
crontab on Dockerfile
  • Dockerfile

    FROM centos:centos6.8
    
    ENV http_proxy http://proxy.daumkakao.io:3128
    ENV https_proxy http://proxy.daumkakao.io:3128
    
    #Install Cron
    RUN yum clean all && yum install epel-release -y && yum install cronie -y
    
    ENV http_proxy ''
    ENV https_proxy ''
    
    # Add crontab file in the cron directory
    ADD crontab /etc/cron.d/hello-cron
    
    # Give execution rights on the cron job
    RUN chmod 0644 /etc/cron.d/hello-cron
    
    # Create the log file to be able to run tail
    RUN touch /var/log/cron.log
    
    # Run the command on container startup
    CMD crond && tail -f /var/log/cron.log
    
  • execution

    $ sudo docker build -t testcron:testcron .
    $ sudo docker run -v /etc/localtime:/etc/localtime:ro testcron:testcron
    
  • ref

  • Dockerfile

    FROM ubuntu:latest
    
    ENV http_proxy http://proxy.daumkakao.io:3128
    ENV https_proxy http://proxy.daumkakao.io:3128
    
    #Install Cron
    RUN apt-get update
    RUN apt-get -y install cron
    
    ENV http_proxy ''
    ENV https_proxy ''
    
    # Add crontab file in the cron directory
    ADD crontab /etc/cron.d/hello-cron
    
    # Give execution rights on the cron job
    RUN chmod 0644 /etc/cron.d/hello-cron
    
    # Create the log file to be able to run tail
    RUN touch /var/log/cron.log
    
    # Run the command on container startup
    CMD cron && tail -f /var/log/cron.log
    
  • execution

    $ sudo docker build -t testcron:testcron .
    $ sudo docker run -v /etc/localtime:/etc/localtime:ro testcron:testcron
    
  • ref

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment