DEV Community

Dimitrios Desyllas
Dimitrios Desyllas

Posted on

Use bash instead of crontab?

As I ask apon laracasts forum I try to containirize a laravel cron scheduler:

This is my Dockerfile:

FROM php:8.1-alpine

# Install 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"]

Enter fullscreen mode Exit fullscreen mode

And this is the entrypoint script /usr/local/bin/entrypoint.sh:

#!/bin/sh
while true
do
    "$@"
    sleep 60
done
Enter fullscreen mode Exit fullscreen mode

But I do not know if my approach will have ant complications and whether in the long term will cause me more trouble that using the crontab.

The idea behind this is because I need only a single command to run every minute seems like a waste to install and run crontab (unless is pre-installed) in my containers.

Do you know if my train of though makes sense and will not cause me trouble in the long term?

Top comments (0)