Be part of JetBrains PHPverse 2026 on June 9 – a free online event bringing PHP devs worldwide together.

ddesyllas's avatar

Is a good idea to use shell instead of cron in order to run laravel scheduler in a containirized laravel application?

I am containirizing a laravel application. What I am making is a container that will run laravel cron scheduler:

FROM php:8.1-alpine

# Load nessesary php module here

COPY . /var/www/html

RUN echo "Installing composer \n" &&\
    php -r "copy('https://getcomposer.org/installer', '/tmp/composer-setup.php');" &&\
    php /tmp/composer-setup.php --install-dir=/bin --filename=composer &&\
    rm -rf /tmp/cpmposer-setup.php &&\
    chmod +x /bin/composer &&\
   cd /var/www/html &&\
   composer install &&\
   rm -rf composer

COPY ./entrypoint/entrypoint_cron.sh /usr/local/bin/entrypoint.sh

RUN echo "Fixing Permissions on Entrypoint Script \n" &&\
    chown root:root /usr/local/bin/entrypoint.sh &&\
    chmod +x /usr/local/bin/entrypoint.sh &&\
    usermod --shell /bin/bash www-data

ENTRYPOINT ["/usr/local/bin/entrypoint.sh"]
CMD ["php","artisan","schedule:run"]

The build image will have the following entrypoint:

#!/bin/sh
while true
do
    "$@"
    sleep 60
done

But what complications my approach may have instead of using crontab?

0 likes
3 replies
Snapey's avatar

If you are building this as your own hobby project then yes, why not.

But if this is for a client, do them and future support people a favour and stick to standard methods of hosting so that it can actually be supported going forwards.

ddesyllas's avatar

@Snapey actually is for a production product that I will always be called to maintained nevertheless. Therefore if you made a docker image with a laravel app in it to run cron via a scheduler which approach would you reccomend?

Please or to participate in this conversation.