Skip to content

Instantly share code, notes, and snippets.



Last active May 23, 2020
What would you like to do?
Cron job scheduling inside a Docker container.
cd /home/testing
timeout 10 python /home/testing/ >>/var/log/crontesting.log 2>&1
# phusion baseimage initiates cron properly
# Use phusion/baseimage as base image. To make your builds reproducible, make
# sure you lock down to a specific version, not to `latest`!
# See for
# a list of version numbers.
FROM phusion/baseimage:0.9.16
# Use baseimage-docker's init system.
CMD ["/sbin/my_init"]
# install Ubuntu packages and other items as needed
# using python example here
# install dependencies from Ubuntu repositories
RUN apt-get -qq update && \
apt-get upgrade -y -o Dpkg::Options::="--force-confdef" -o DPkg::Options::="--force-confold" && \
apt-get install -y -q \
git \
build-essential \
python \
python-yaml \
python-dev \
python-setuptools \
python-pip \
&& \
apt-get clean && rm -rf /var/lib/apt/lists/* /tmp/* /var/tmp/*
# install python dependencies
RUN easy_install -U setuptools && \
pip install -U pip
# add cron scripts and make executable
RUN mkdir /home/testing
ADD /home/testing/
ADD /home/testing/
RUN chmod +x /home/testing/
# cron schedule
ADD mycrontab /home/testing/mycrontab
RUN crontab /home/testing/mycrontab
# Jobs:
# m h dom mon dow command
* * * * * /home/testing/
#!/usr/bin/env python
import datetime
print "Cron job has run at %s"
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment