Sign inSign up

intekhabrizvi/php-cli-7.1-cron

By intekhabrizvi

Updated over 6 years ago

Custom made image to run cron inside container along with PHP7.1 CLI support.

Image
0

215

intekhabrizvi/php-cli-7.1-cron repository overview

Running Cron inside Docker container

This tailor-made alpine based image will let you run cron inside a Docker container.

Features

  • Timezone support.
  • Pre-installed common PHP 7.1 cli packages (GD, MongoDB, SOAP, PDO_MYSQL).
  • External crontab file loading using volume.
  • Throw cron logs on externaly mounted volume.

Running a container

Below is a command to run a Docker container using this image.

docker run --rm -e "TZ=America/Phoenix" --name="alpine-cron-sample" -d \
-v /ABS_PATH/crontabs:/var/spool/cron/crontabs \
-v /ABS_PATH/logs:/var/log/cron \
intekhabrizvi/php-cli-7.1-cron

Params Explanation

NameExplanation
"TZ=America/Phoenix"By default container start with UTC as timezone but you can use this param to change containers timezone. Acceptable values can be found at [http://www.timezoneconverter.com/cgi-bin/zoneinfo]
/ABS_PATH/crontabsAn absolute path to the local folder where you will store your crontab file. Inside this folder you should have a single file named root and that file will have all your commands just like crontab file. Read Example crontab file
/ABS_PATH/logsAn absolute path to the local folder where you want cron logs files to be created.

Example crontab file

Below is an example content of your starting crontab file.

*/1 * * * * echo "This is a test" >> /var/log/cron/cron.log 2>&1
*/1 * * * * php -m >> /var/log/cron/cron.log 2>&1

Dockerfile

Below is the content of Dockerfile I used to build the latest version of this image.

FROM php:7.1-cli-alpine
RUN apk add tzdata libxml2-dev freetype libpng libjpeg-turbo freetype-dev libpng-dev libjpeg-turbo-dev
RUN apk add --no-cache $PHPIZE_DEPS
RUN docker-php-ext-install xml pdo_mysql mysqli bcmath soap gd zip
RUN pecl install mongodb && docker-php-ext-enable mongodb
RUN apk del --no-cache $PHPIZE_DEPS
RUN mkdir -p /var/log/cron && mkdir -m 0644 -p /var/spool/cron/crontabs && touch /var/log/cron/cron.log && mkdir -m 0644 -p /etc/cron.d
CMD ["crond", "-f", "-l", "8"]

License

MIT Provide as-is basis, I am not responsible for anything

Tag summary

Content type

Image

Digest

Size

-

Last updated

over 6 years ago

docker pull intekhabrizvi/php-cli-7.1-cron