I have a docker file which has some of the following
ADD ./.docker/config/cron/$BUILD_ENV.cron /etc/cron.d/cron
RUN chmod 0644 /etc/cron.d/cron
RUN touch /var/log/cron.log
and the file ends with
CMD cron && tail -f /var/log/cron.log
My cron file comprises of
* * * * * root /usr/local/bin/php /var/www/pub/artisan schedule:run >> /var/log/cron.log 2>&1
With the extra line of course.
If I create the file with the following the cron runs.
* * * * * root echo "Hello world" >> /var/log/cron.log 2>&1
However my laravel artisan isn't firing? Any help would be appreciated. The cron is created as root, and executed as root.
My Answer:
It looks like the issue might be with the path to the PHP binary in your cron job command. Instead of using `/usr/local/bin/php`, you should use the full path to the PHP binary inside your Docker container.
You can find the full path to the PHP binary by running the following command inside your Docker container:
bash
which php
Once you have the full path to the PHP binary, update your cron job command to use that path. For example, if the full path to the PHP binary is `/usr/bin/php`, your cron job command should look like this:
bash
* * * * * root /usr/bin/php /var/www/pub/artisan schedule:run >> /var/log/cron.log 2>&1
Make sure to restart your Docker container after making this change to ensure that the new cron job command is picked up.
Rate this post
5 of 5 based on 9712 votesComments