Run Cron jobs inside Docker container

This Dockerfile can be used to execute python code, scheduled by a Cron job.

The basic steps followed:

  1. Load a random python application which is executed from the index.py file.
  2. Make sure cron is installed in the image.
  3. Load necessary environment variables from the env file (.env) specifically created to load the configuration (restrict unix permissions) availabe to os.environ().
  4. The python app start command is written into an executable file script.sh. The execution of this script will be finally scheduled by cron.

The BASH_ENV environment variable can be used to preload environment variables at the cronjob context.

Environment varaibles loaded with BASH_ENV are only available to the cron job loading the BASH_ENV variable. In fact, entries in the crontab won’t share the same cron job context.