How to run cron jobs inside php-fpm-alpine docker container? How to run cron jobs inside php-fpm-alpine docker container? docker docker

How to run cron jobs inside php-fpm-alpine docker container?


When you need to run multiple processes in your docker container a solution is to use supervisord as the main instruction. Docker will start and monitor supervisord which in turn will start your other processes.

Docker File Example:

FROM debian:9...CMD ["/usr/bin/supervisord", "-c", "/etc/supervisor/my.conf"]

Supervisord config example (/etc/supervisor/my.conf):

[supervisord]nodaemon=true[program:cron]command=/usr/sbin/crond -f -l 8stdout_logfile=/dev/stdoutstderr_logfile=/dev/stderrstdout_logfile_maxbytes=0stderr_logfile_maxbytes=0autorestart=true[program:php-fpm]command=docker-php-entrypoint php-fpm

Note that it is desirable to configure supervisord to output the logs to /dev/stdout and /dev/stderr to allow docker to handle these logs. Otherwise you risk your container to slow down over time as the amount of file writes increases.